Custom fonts and XML layouts (Android)

后端 未结 18 2124
执念已碎
执念已碎 2020-11-22 07:21

I\'m trying to define a GUI layout using XML files in Android. As far as I can find out, there is no way to specify that your widgets should use a custom font (e.g. one you\

18条回答
  •  青春惊慌失措
    2020-11-22 07:25

    Using DataBinding :

    @BindingAdapter({"bind:font"})
    public static void setFont(TextView textView, String fontName){
     textView.setTypeface(Typeface.createFromAsset(textView.getContext().getAssets(), "fonts/" + fontName));
    }
    

    In XML:

    
    

    font file must be in assets/fonts/

提交回复
热议问题