change font of all textviews

后端 未结 5 820
一向
一向 2021-01-03 02:28

is there a way to change the fonts of all textviews in a layout?

currently im using this to change fonts manually.

TextView txtAppName = (TextView) f         


        
5条回答
  •  礼貌的吻别
    2021-01-03 03:19

    You can make your own View that will set you font and use it

    public class MyTextView extends TextView {
         public MyTextView(Context context) {
            super(context, attrs, defStyle);
            setFont(context);
         }
    
         private void setFont(Context context) {
            Typeface font = Typeface.createFromAsset(context.getAssets(), YOUR_FONT);
            setTypeface(font);
         }
    }
    

提交回复
热议问题