【问题标题】:Android RunTime exception "Font asset not found" for .woff font files in android nougatandroid nougat 中 .woff 字体文件的 Android 运行时异常“未找到字体资产”
【发布时间】:2017-07-09 14:45:25
【问题描述】:

我正在开发一个应用程序,我需要在其中使用 .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 文件夹中字体的屏幕截图。 asset folder with woff fonts

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

提前致谢 克里希纳

【问题讨论】:

    标签: android-7.0-nougat woff


    【解决方案1】:

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

    【讨论】:

    • 嗨克里斯,你知道谷歌上已经在跟踪这个的任何错误吗?我也注意到了这一点。
    • @clu 不幸的是没有。我只是通过自己寻找答案才发现这一点。我希望我已将找到的来源添加到答案中,因为我再也无法在浏览器历史记录中找到它了。 :(
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-10-20
    • 2018-12-07
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多