android-7.0-nougat - Android Nougat 中 .woff 字体文件的 Android 运行时异常 "Font asset not found"

标签 android-7.0-nougat woff

我正在开发一个应用程序,我需要使用 .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/

相关文章:

java - 使用方法引用定义 BroadcastReceiver.onReceive

fonts - 字体名称中的合法字符是什么?

android - 如何从牛轧糖上传选定的视频,路径返回 null

android - 标准 Seekbar 的进度条不出现

Android:为电信注册新的PhoneAccount

avd - 无法在模拟器中启动 AVD。输出 : sh: 1: glxinfo:

angular - 如何在没有 web.config 的情况下从 Azure 公开和提供 WOFF 文件?

ruby-on-rails-3 - Rails 3 网络字体 (woff) mime 类型

css - 打印时 Microsoft Edge @font-face 不应用

python - Pygame从外部字体文件加载字体