5

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

2 Answers2

1

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

A.S.
  • 4,574
  • 3
  • 26
  • 43
  • Thanks for your information , but i have already created the same you have suggest me, but the thing is the font face for all the view must be same so i should create a class which extend the component for all the type of views. So what i need a class which will affect the font face of all the view in android like style in default.... – Mohammed Rizwan Oct 09 '13 at 06:28
1

You have at least 2 ways:

  • create your own TextView class and set fontFace in constructor
  • you can use custom LayoutInflater. And every time view gets inflated check that it is textView (or other view not extending textView but having font settings) and set correct fontFace settings.
Community
  • 1
  • 1
Leonidos
  • 10,482
  • 2
  • 28
  • 37