如何在eclipse中使用自定义字体?

时间:2012-03-10 20:06:44

标签: android

  

可能重复:
  Android - Using Custom Font

我正在用阿拉伯语创建一个应用程序 并有一个我想要使用的自定义字体 谁能告诉我我应该在我的java类中使用的代码 我试过这个

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

但是字体的结尾是一个错误 令牌“font”上的语法错误,此令牌后预期的VariableDeclaratorId 有人可以帮忙!

2 个答案:

答案 0 :(得分:5)

试试这个,就像添加this lol

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

答案 1 :(得分:2)

将自定义字体文件保存在fonts文件夹中的assets文件夹中。

例如:

assets/fonts/trado.ttf

enter image description here

并确保您的字体扩展名(例如 ttf )为小写字母。