Is it possible to set a custom font for entire of application?

后端 未结 25 2664
日久生厌
日久生厌 2020-11-22 02:44

I need to use certain font for my entire application. I have .ttf file for the same. Is it possible to set this as default font, at application start up and then use it else

25条回答
  •  孤独总比滥情好
    2020-11-22 03:22

    its very simple... 1.Download and put ur custom font in assets..then write one separate class for text view as follows: here i used futura font

    public class CusFntTextView extends TextView {
    
    public CusFntTextView(Context context, AttributeSet attrs, int defStyle) {
        super(context, attrs, defStyle);
        init();
    }
    
    public CusFntTextView(Context context, AttributeSet attrs) {
        super(context, attrs);
        init();
    }
    
    public CusFntTextView(Context context) {
        super(context);
        init();
    }
    
    private void init() {
        if (!isInEditMode()) {
            Typeface tf = Typeface.createFromAsset(getContext().getAssets(), "Futura.ttf");
            setTypeface(tf);
        }
    }
    

    }

    and do the following in xml :

     
    

提交回复
热议问题