当前位置: 代码迷 >> Android >> 关于android增添第三方字体的方法
  详细解决方案

关于android增添第三方字体的方法

热度:74   发布时间:2016-05-01 12:17:05.0
关于android添加第三方字体的方法
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" />
  相关解决方案