android添加第三方字体,type=Typeface.createFromFile("@assets/fonts/hwxk.ttf");
tv=(TextView) findViewById(R.id.index_grid_detail_text);
tv.setTypeface(type);
提示 native typeface cannot be made
------解决方案--------------------
如果font已经放在工程的assets目录中,这样改代码:
Typeface type= Typeface.createFromAsset(getAssets(),"fonts/hwxk.ttf");
tv=(TextView) findViewById(R.id.index_grid_detail_text);
tv.setTypeface(type);
从SD卡中自定义字体:
Typeface type= Typeface.createFromFile(new File(Environment.getExternalStorageDirectory(), "/assets/fonts/hwxk.ttf"));
tv=(TextView) findViewById(R.id.index_grid_detail_text);
tv.setTypeface(type);
在AndroidManifest.xml文件中添加sdcard许可:
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />