我正在开发一个应用程序,我需要使用 .woff 字体。我编写了以下代码来从 .woff 文件中获取字体类型并设置到 textview 中。
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 设备上给出了异常( Font asset not found fonts/AvenirLTStd-Black.woff )。 我已经在 android 7.0 设备上测试了 ttf 和 otf 字体,并且工作正常。只有 woff 字体会出现此异常。
我还附上了屏幕截图,其中显示了 asset/fonts 文件夹中的字体。 asset folder with woff fonts
任何人都可以帮助我”这里出了什么问题吗?
提前致谢 克里希纳
最佳答案
Android 7.0 和 7.1 中的 WOFF 支持似乎至少部分被破坏,此类字体可从包 assets
目录中卸载。如果您支持 Nougat,您最好的选择是获取字体的 TTF 或 OTF 版本并使用它们。
关于android-7.0-nougat - Android Nougat 中 .woff 字体文件的 Android 运行时异常 "Font asset not found",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42342572/