Android - 使用自定义字体 [英] Android - Using Custom Font
问题描述
我将自定义字体应用于 TextView
,但它似乎没有改变字体.
I applied a custom font to a TextView
, but it doesn't seems to change the typeface.
这是我的代码:
Typeface myTypeface = Typeface.createFromAsset(getAssets(), "fonts/myFont.ttf");
TextView myTextView = (TextView)findViewById(R.id.myTextView);
myTextView.setTypeface(myTypeface);
谁能帮我解决这个问题?
Can anyone please get me out of this issue?
推荐答案
在 Mobiletuts+ 上有非常好的 Android 文本格式教程.快速提示:自定义 Android字体
On Mobiletuts+ there is very good tutorial on Text formatting for Android. Quick Tip: Customize Android Fonts
现在自己测试了.这是解决方案.您可以使用名为 fonts 的子文件夹,但它必须位于 assets
文件夹中,而不是 res
文件夹中.所以
Tested it myself now. Here is the solution. You can use a subfolder called fonts but it must go in the assets
folder not the res
folder. So
资产/字体
还要确保字体结尾我的意思是字体文件本身的结尾都是小写的.换句话说它不应该是myFont.TTF
而是myfont.ttf
这种方式必须是小写
Also make sure that the font ending I mean the ending of the font file itself is all lower case. In other words it should not be myFont.TTF
but myfont.ttf
this way must be in lower case
这篇关于Android - 使用自定义字体的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!