2012-03-10 51 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

相關問題