2012-06-16 43 views
1

我有一個字體文件love.ttf(5mb)。我已將它放入資產文件夾。 這是我的代碼設置字體文本視圖android(來自字體文件)

@Override 
public void onCreate(Bundle savedInstanceState) { 
    super.onCreate(savedInstanceState); 
    setContentView(R.layout.main); 
    TextView tv=(TextView)findViewById(R.id.textView1); 
    Typeface tf=Typeface.createFromAsset(getAssets(),"love.ttf");; 
    tv.setTypeface(tf,Typeface.NORMAL); 
    tv.setTextSize(20); 
} 

的main.xml文件

<?xml version="1.0" encoding="utf-8"?> 
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="fill_parent" 
    android:layout_height="fill_parent" 
    android:background="#4B67A1" 
    android:orientation="vertical" >  
    <TextView 
     android:id="@+id/textView1" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:text="おはようございます。" />  
</LinearLayout> 

當我運行它,我無法看到的文本! 如何加載大字體? 請幫幫我! 謝謝

+0

看來這個問題應該是ttf文件。 – Jitendra

+0

你解決了這個問題嗎?我遇到了這個問題,這實際上適用於Android 2.3+,但不是<2.2。 –

回答

2

所以,首先會有兩個可能的原因,它不起作用。

  1. 檢查您的字體是否支持日文字符。
  2. 您的字體文件路徑不正確。

    TextView tv = (TextView) findViewById(R.id.textView1); 
    Typeface tf=Typeface.createFromAsset(getAssets(),"fonts/love.ttf"); 
    

你應該有一個名爲fontsassets文件夾下一個子文件夾。然後檢查你是否有正確的字體後綴。

+0

這是一個字體http://cooltext.com/Download-Font-+%E3%82%89%E3%81%B6+S2G+Love 我有變化 Typeface tf = Typeface.createFromAsset(getAssets() , 「字體/ love.ttf」); 但它仍然... –

+0

您是否已將字體添加到assets/fonts文件夾中?如果它仍然不起作用,你的字體不支持日文字符,請改變font.im不支持字體,但這種字體似乎不支持你想要的字符。 – Sajmon

+0

是的,我已經將字體添加到資產/文件夾,這是一種日文字體,但是,我可以看到文本。字體文件的大小是5MB,我認爲字體文件很大 –

0

我建議你不要直接在Asset文件夾中保存字體,而是在它下面創建字體文件夾,並在裏面保存love.ttf字體。

然後你可以執行如下魔術。

TextView tv=(TextView)findViewById(R.id.custom); 
    Typeface face=Typeface.createFromAsset(getAssets(), "fonts/love.ttf"); 
    tv.setTypeface(face); 
+0

這是字體http://cooltext.com/Download-Font-+%E3%82%89%E3%81%B6+S2G+Love 我認爲字體文件很大!大小:5mb –

+0

我試過你的字體!它的工作完美無缺! –

+0

android 2.2?我在android 2.2中寫道,但我可以看到文本,你顯示的是什麼文本? –