2013-07-15 65 views
0

我有textview。我無法顯示日本特徵。所以下載了字體到Assets/fonts文件夾。我試過這個代碼如何更改TextView的字體?

Typeface tf = Typeface.createFromAsset(getAssets(), 
      "fonts/ipag.ttf"); 
    TextView tv=(TextView) findViewById(R.id.name); 
    tv.setTypeface(tf); 

但是應用程序無法正常工作。應該改變什麼?

+0

只要字體位於資產文件夾內,這段代碼就會很好,所以錯誤必須在其他方面。我需要更多的信息。 – amatellanes

回答

0

此代碼有工作對我來說:

首先聲明字體:

Typeface font; 

中的onCreate內第二:
font = Typeface.createFromAsset(getAssets(), "myfont.ttf");

第三:也是裏面的onCreate:

myTest = (Button) findViewById(R.id.myTest); 
myTest.setTypeface(font); 

我的應用程序可以改變這些之一languaje與日本,和它運作良好。這是使用的字體: http://wowslider.com/styles/miso-bold-webfont.ttf。順便說一句,這個字體是在Assets文件夾裏面的。