Custom fonts and XML layouts (Android)

后端 未结 18 2130
执念已碎
执念已碎 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:30

    I might have a simple answer for the question without extending the TextView and implementing a long code.

    Code :

     TextView tv = (TextView) findViewById(R.id.textview1);
        tv.setTypeface(Typeface.createFromAsset(getAssets(), "font.ttf"));
    

    Place the custom font file in assets folder as usual and try this. It works for me. I just dont understand why peter has given such a huge code for this simple thing or he has given his answer in old version.

提交回复
热议问题