Android - Fonts in Application

家住魔仙堡 提交于 2020-01-16 11:20:40

问题


I have added an external font in /assets directory, and manually doing setFacetype(font). Isn't there a general way to set the whole application to use a specific font if you have added it external? Or do you have to use Android's selected fonts in order to achieve this?


回答1:


You cannot use your custom fonts through to whole application in a general way.

You cannot set your custom fonts through xml files.

You have to use the Typeface functions in your code to use your custom fonts within your application.




回答2:


tv=(TextView)findViewById(res);
Typeface font = Typeface.createFromAsset(this.getAssets(), "MYFONT.TTF"); 
tv.setTypeface(font);

This also how to use it in a textview.

For whole application go to Using a custom typeface in Android.

and go to Manish Singla answer




回答3:


Typeface mTypeface =  Typeface.createFromAsset(getAssets(), "YOUR FONT NAME");
textview.setTypeface(mTypeface, Typeface.NORMAL);


来源:https://stackoverflow.com/questions/9531110/android-fonts-in-application

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!