Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <com.app.customview.DefaultTextView
- android:layout_width="wrap_content"
- android:layout_height="wrap_content"
- android:text="@string/especifico_label"
- android:textSize="28sp"
- android:layout_marginTop="9dp"
- android:layout_gravity="center"/>
- public class DefaultTextView extends android.support.v7.widget.AppCompatTextView {
- private boolean isLight = false;
- public DefaultTextView(Context context) {
- super(context);
- setFont();
- }
- public DefaultTextView(Context context, AttributeSet attrs) {
- super(context, attrs);
- setAttr(context, attrs);
- setFont();
- }
- public DefaultTextView(Context context, AttributeSet attrs, int defStyleAttr) {
- super(context, attrs, defStyleAttr);
- setAttr(context, attrs);
- setFont();
- }
- private void setAttr(Context context, AttributeSet attrs) {
- TypedArray typedArray = context.obtainStyledAttributes(attrs, R.styleable.Font, 0, 0);
- isLight = typedArray.getBoolean(R.styleable.Font_isLight, false);
- typedArray.recycle();
- }
- private void setFont() {
- if(!isInEditMode()) {
- String tf;
- if(getTypeface()!=null) {
- switch (getTypeface().getStyle()) {
- case Typeface.ITALIC:
- tf = "fonts/segoeuii.ttf";
- break;
- default:
- tf = "fonts/segoeui.ttf";
- break;
- }
- } else {
- tf = "fonts/segoeui.ttf";
- }
- if(isLight) {
- tf = "fonts/segoeuil.ttf";
- }
- setTypeface(Typeface.createFromAsset(getContext().getAssets(), tf));
- setTextColor(Color.WHITE);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement