Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?

like image 640
Kit Ramos Avatar asked Dec 26 '22 23:12

Kit Ramos


2 Answers

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"/>
like image 180
Vipul Avatar answered Jan 11 '23 20:01

Vipul


Put Your different font files in assets folder...

TextView mytextView=(TextView)findViewById(R.id.txtbx);
Typeface fonttype=Typeface.createFromAsset(getAssets(),"fonts/fontname.ttf");
mytextView.setTypeface(fonttype);
like image 29
selva_pollachi Avatar answered Jan 11 '23 20:01

selva_pollachi