2014年1月5日星期日

About Methods android add third-party fonts

android add third-party fonts , type = Typeface.createFromFile ("@ assets / fonts / hwxk.ttf");
tv = (TextView) findViewById (R.id.index_grid_detail_text);
tv.setTypeface (type);
Tip native typeface cannot be made
------ Solution ---------------------- ----------------------
assets if the font has been placed in the project directory , so change the code :
Typeface type= Typeface.createFromAsset(getAssets(),"fonts/hwxk.ttf");
tv=(TextView) findViewById(R.id.index_grid_detail_text);
tv.setTypeface(type);

custom font from the SD card :
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 AndroidManifest.xml file:
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />

------ eference ------------------------------------- -
createFromFile need to specify the path to the file , right , @ assets / fonts / hwxk.ttf this count?
use this to try Typeface.createFromAsset (getAssets (), "fonts / hwxk.ttf")
------ eference ------------- --------------------------
you say that method does not work . I tried. The same error
------ eference ------------------------------------- -
your fonts on which the
------ eference ---------------------------- -----------
assets / fonts / qqqq.ttf
------ eference ------------------- --------------------
be useful , mark it!

没有评论:

发表评论