Search code examples
androidtextviewcustom-font

Add custom font for complete android application


In my application I need to use helvetica font for all the textviews and edit-text fields. Is there any way to do this other than using settypeface method for every textview ? Any suggestion would be a great help.

Thanks in advance !


Solution

  • I figured it out by my self. This is the code I used. I create custom TextView which has custom font as default font.

    public class MyTextView extends TextView {
    
        public MyTextView(Context context, AttributeSet attrs, int defStyle) {
            super(context, attrs, defStyle);
            init();
        }
    
        public MyTextView(Context context, AttributeSet attrs) {
            super(context, attrs);
            init();
        }
    
        public MyTextView(Context context) {
            super(context);
            init();
        }
    
        private void init() {
            Typeface tf = Typeface.createFromAsset(getContext().getAssets(), "font/chiller.ttf");
            setTypeface(tf ,1);
    
        }
    
    }