我正在开发一个应用程序,我需要在其中使用 .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 assets not found fonts/AvenirLTStd-Black.woff)。我已经在 android 7.0 设备上测试了 ttf 和 otf 字体,它工作正常。只有 woff 字体给出了这个例外。
我还附上了屏幕截图,它显示了assets/fonts 文件夹中的字体。带有 woff 字体的资产文件夹
谁能帮帮我”这里有什么问题?
在此先感谢克里希纳