Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to use a same custom fontface for all the view in android?

i want use all the component in android which having the same font type face, for that i am creating a individual custom class for each component like CustomTextView, CustomEditText, etc,..

So instead of creating a individual class for each component can i create a view CustomView class that will automatically apply style for all the components in android

like image 631
Mohammed Rizwan Avatar asked Nov 01 '22 13:11

Mohammed Rizwan


1 Answers

Just declare your own TextView and use it in your XML, it should appear in the custom Views

 public class MyTextView extends TextView {

public MyTextView(Context context, AttributeSet attrs, int defStyle) {
    super(context, attrs, defStyle);
    setType(context);
}

public MyTextView(Context context, AttributeSet attrs) {
    super(context, attrs);
    setType(context);
}

public MyTextView(Context context) {
    super(context);
    setType(context);
}

private void setType(Context context){
    this.setTypeface(Typeface.createFromAsset(context.getAssets(), "chalk_board.ttf"));
}

Oh dam u want it globally for all views, so this is the wrong approach.... Sorry for that

like image 152
A.S. Avatar answered Nov 08 '22 14:11

A.S.