2012-03-10 52 views
2

可能重复:
Android - Using Custom Font如何在eclipse中使用自定义字体?

我创造阿拉伯语 的应用程序,并有一个我想使用 自定义字体可有人告诉我,我的代码应该用我的java class 我试过

TextView txt = (TextView) findViewById(R.id.custom_font); 
Typeface font = Typeface.createFromAsset(getAssets(), "trado.ttf"); 
txt.setTypeface(font); 

但是结尾线说,字体theres一个错误,说 令牌“字体”的语法错误,VariableDeclaratorId预计在此令牌后 有人可以帮助!

+0

重复的文章,请参阅Android - 使用自定义字体http://stackoverflow.com/q/3651086/594773 – 2012-03-10 20:15:12

+0

这里的一切都很好,您是否已将字体添加到资源文件夹? – 2012-03-10 20:16:29

+0

是的,我做了,但我得到一个错误! – user1223679 2012-03-10 20:18:28

回答

5

试试这个,在加入this

TextView txt = (TextView) findViewById(R.id.custom_font); 
Typeface font = Typeface.createFromAsset(this.getAssets(), "trado.ttf"); 
txt.setTypeface(font); 
2

保存您的自定义字体文件的文件夹fontsassets文件夹内。

例如:

assets/fonts/trado.ttf 

enter image description here

,并确保您的字体扩展(即TTF你的情况)是小写。

+0

我已经发现如何做到这一点 – user1223679 2012-03-10 21:40:33

+0

问题是什么? – waqaslam 2012-03-10 21:41:17

相关问题