0

I add the third party font in android. And I put the font in the root of assets/fonts/qqqq.ttf

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

But it has the error like: native typeface cannot be made.

What is the problem? anyone knows this? thanks very much!

4

2 回答 2

1

Change your code as if font is placed within assets dir in Project:

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

and for Creating Custom font from Sdcard change your code as:

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

Add sdcard permission in AndroidManifest.xml file:

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

Write below code instead of your code after setContentView();, may be it will solve your problem.

// 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);

And see below link for more information.

Customize Android Fonts

于 2012-11-30T08:27:40.767 回答