Search code examples
androidfontsdefaulttruetype

change Default font for Android App


Okay, I know how to change what font is used on individual textboxes in my app, but I want ALL the text in my app to use this custom font and color, and currently the only way I can think of to do his is to reference each box and set them to the proper font and color. while it's doable it seems rather a clunky method, is there a better way?


Solution

  • You can create custom TextView and reffer it everywhere.

    public class TypefacedTextView extends TextView {
    
        public TypefacedTextView(Context context, AttributeSet attrs) {
            super(context, attrs);
    
            Typeface typeface = Typeface.createFromAsset(context.getAssets(), fontName);
            setTypeface(typeface);
        }
    }
    

    Inside view.xml

    <packagename.TypefacedTextView
                 android:layout_width="fill_parent"
                 android:layout_height="wrap_content"
                 android:text="Hello"/>