2011-06-07 27 views
8

可能重複:
how to change the font on the text view in android?如何在android中爲TextView設置字體?

我嘗試了很多設置字體在我的應用程序TextView的。但似乎沒有辦法在android中設置字體。我想通過xml爲我的所有TextView設置Arial字體。我將Arial.ttf添加到我的資產中,但仍然無法在xml中設置樣式。請找到我的出路。

+1

這是一個類似的問題/答案,我認爲可能會有幫助:http://stackoverflow.com/questions/2888508/how-to-change-the-font-on-the-text-view-in-android – plainjimbo 2011-06-07 20:56:22

回答

23

AFAIK你不能在XML做到這一點,你必須這樣做,在代碼:

Typeface tf = Typeface.createFromAsset(getAssets(), 
      "fonts/Arial.otf"); 
TextView tv = (TextView) findViewById(R.id.CustomFontText); 
tv.setTypeface(tf) 
+0

感謝男士們......我明白了。 – Panache 2011-06-08 08:38:52

相關問題