2

How can i set text color and text size in the class below

public class MyTextView extends TextView {
    public MyTextView(Context context, AttributeSet attrs, int defStyle) {
        super(context, attrs, defStyle);
        init();
    }
    public MyTextView(Context context, AttributeSet attrs) {
        super(context, attrs);
        init();
    }
    public MyTextView(Context context) {
        super(context);
        init();
    }
    public void init() {
        Typeface tf = Typeface.createFromAsset(getContext().getAssets(), "font/chiller.ttf");
        setTypeface(tf ,1);
    }
    }
Dimitri
  • 1,924
  • 9
  • 43
  • 65

1 Answers1

2

In your init use setTextColor and setTextSize

  public void init() {
    Typeface tf = Typeface.createFromAsset(getContext().getAssets(), "font/chiller.ttf");
    setTypeface(tf ,1);
    this.setTextColor(Color.RED);
    this.setTextSize(20f);
} 

If you are looking for custom attributes check this

Setting color of a Paint object in custom view

Community
  • 1
  • 1
Raghunandan
  • 132,755
  • 26
  • 225
  • 256