1

フォントファイル love.ttf (5mb) があります。私はそれを資産フォルダに入れていた。これは私のコードです

 @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>

実行すると、テキストが表示されません!!! 大きなフォントを読み込むには?私を助けてください!ありがとう

4

2 に答える 2

2

したがって、まず、機能しない理由として 2 つの可能性があります。

  1. フォントが日本語の文字をサポートしているかどうかを確認してください。
  2. フォントファイルのパスが間違っている可能性があります。

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

assetsフォルダーに、次の名前のサブフォルダーが必要fontsです。次に、フォントの正しい接尾辞があるかどうかも確認します。

于 2012-06-16T13:57:07.263 に答える
0

フォントをAssetフォルダーに直接保存するのではなく、その下とその中にlove.ttfフォントを保存するフォントフォルダーを作成することをお勧めします。

その後、以下のように魔法を実行することができます。

  TextView tv=(TextView)findViewById(R.id.custom); 
  Typeface face=Typeface.createFromAsset(getAssets(), "fonts/love.ttf"); 
  tv.setTypeface(face); 
于 2012-06-16T14:02:54.190 に答える