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

后端 未结 25 2657
日久生厌
日久生厌 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条回答
  •  -上瘾入骨i
    2020-11-22 03:08

    I would also suggest extending TextView and other controls, but it would be better I consider to set up font in constructs.

    public FontTextView(Context context) {
        super(context);
        init();
    }
    
    public FontTextView(Context context, AttributeSet attrs) {
        super(context, attrs);
        init();
    }
    
    public FontTextView(Context context, AttributeSet attrs, int defStyle) {
        super(context, attrs, defStyle);
        init();
    }
    
    protected void init() {
        setTypeface(Typeface.createFromAsset(getContext().getAssets(), AppConst.FONT));
    }
    

提交回复
热议问题