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

Android 码拜 9年前 (2015-05-10) 1443次浏览 0个评论
 

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

createFromFile需要指定的是文件的路径吧,@assets/fonts/hwxk.ttf这个算什么?
用这个试试Typeface.createFromAsset(getAssets(), “fonts/hwxk.ttf”)
你说的那个方法也不行。我试过了。同样的错误
你的字体放在哪的
assets/fonts/qqqq.ttf
40分
如果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" />
有用,mark一下!
看下路径名,是不是代码中的font和asset中的文件名不一样,我就是写错了,报那个错误的,一样就ok了

CodeBye 版权所有丨如未注明 , 均为原创丨本网站采用BY-NC-SA协议进行授权 , 转载请注明关于android添加第三方字体的方法
喜欢 (0)
[1034331897@qq.com]
分享 (0)

文章评论已关闭!