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

后端 未结 25 2963
日久生厌
日久生厌 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:17

    package com.theeasylearn.demo.designdemo;
    import android.content.Context;
    import android.graphics.Typeface;
    import android.util.AttributeSet;
    import android.widget.TextView;
    
    public class MyButton extends TextView {
    
        public MyButton(Context context, AttributeSet attrs, int defStyle) {
            super(context, attrs, defStyle);
            init();
        }
    
        public MyButton(Context context, AttributeSet attrs) {
            super(context, attrs);
            init();
        }
    
        public MyButton(Context context) {
            super(context);
            init();
        }
    
        private void init() {
    
                Typeface tf =
                        Typeface.createFromAsset(
                                getContext().getAssets(), "angelina.TTF");
                setTypeface(tf);
    
        }
    
    }
    

提交回复
热议问题