2

我正在开发一个应用程序,我需要在其中使用 .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 字体的资产文件夹

谁能帮帮我”这里有什么问题?

在此先感谢克里希纳

4

1 回答 1

2

Android 7.0 和 7.1 中的 WOFF 支持似乎至少部分被破坏,这些字体无法从包assets目录中卸载。如果您支持 Nougat,最好的选择是获取字体的 TTF 或 OTF 版本并使用它们。

于 2017-06-05T22:15:29.520 回答