0

Androidにサードパーティのフォントを追加します。そして、フォントを assets/fonts/qqqq.ttf のルートに置きます

type=Typeface.createFromFile("@assets/fonts/hwxk.ttf"); 
 tv=(TextView) findViewById(R.id.index_grid_detail_text);
 tv.setTypeface(type);

しかし、次のようなエラーがあります:ネイティブ書体を作成できません。

何が問題ですか?誰もこれを知っていますか?どうもありがとう!

4

2 に答える 2

1

フォントが Project の assets ディレクトリ内に配置されているかのようにコードを変更します。

Typeface type= Typeface.createFromAsset(getAssets(),"fonts/hwxk.ttf");
tv=(TextView) findViewById(R.id.index_grid_detail_text);
tv.setTypeface(type);

また、Sdcard からカスタム フォントを作成するには、コードを次のように変更します。

Typeface type= Typeface.createFromFile(new File(Environment.getExternalStorageDirectory(), "/assets/fonts/hwxk.ttf"));
tv=(TextView) findViewById(R.id.index_grid_detail_text);
tv.setTypeface(type);

ファイルに SD カードのアクセス許可を追加しAndroidManifest.xmlます。

<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
于 2012-11-30T07:45:33.457 に答える
1

の後のコードではなく、以下のコードを記述してsetContentView();ください。問題が解決する可能性があります。

// text view label
TextView mTextView1 = (TextView) findViewById(R.id.TextView1);

// Loading Font Face
Typeface tf = Typeface.createFromAsset(getAssets(), "DroidSansFallback.ttf");

// Applying font
mTextView1.setTypeface(tf);

詳細については、以下のリンクを参照してください。

Android フォントのカスタマイズ

于 2012-11-30T08:27:40.767 に答える