2
我正在开发一个应用程序,我需要使用.woff字体。我已经写了下面的代码来从.woff文件中获取字体类型的面并将其设置为textview。Android RunTime异常“未找到字体资源”,用于Android中的.woff字体文件nougat
hellofont = getFont("fonts/AvenirLTStd-Black.woff");
//welcomefont = getFont ("fonts/AvenirLTStd-Heavy.woff");
thankufont = getFont("fonts/RobotoCondensed-Bold.ttf");
TextView text1 = (TextView) findViewById(R.id.text1id);
text1.setTypeface(hellofont);
TextView text2 = (TextView) findViewById(R.id.text2id);
text2.setTypeface(thankufont);
public Typeface getFont(String fontName){
try {
Typeface content = Typeface.createFromAsset(this.getAssets(), fontName);
return content;
}
catch(RuntimeException e)
{
Toast.makeText(this,e.getMessage(),Toast.LENGTH_LONG).show();
}
return null;
}
此代码在Android 5.0和6.0设备上正常工作。但它在Android 7.0设备上发出异常(字体资产未找到字体/ AvenirLTStd-Black.woff)。 我已经在Android 7.0设备上测试过ttf和otf字体,并且工作正常。只有woff字体才会给出这个例外。
我附加了屏幕截图,其中显示了在assests/fonts文件夹中的字体。 asset folder with woff fonts
谁能帮助我”有什么问题吗?提前
感谢 克里希纳
嗨克里斯,你知道谷歌上的任何错误已经跟踪这个吗?我也注意到了这一点。 – clu
@clu un幸运的是没有。我只是通过自己寻找答案才发现这一点。我希望我已经将我找到的来源添加到答案中,因为我无法再在浏览器历史记录中找到它。 :( –