Android RunTime exception “Font asset not found” for .woff font files in android nougat

China☆狼群 提交于 2019-12-10 10:55:57

问题


I am developing one application, where I need to use .woff fonts. I have written the following code to get font type face from .woff file and set into 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;

}

This code works fine on android 5.0 and 6.0 devices. But it is giving exception ( Font asset not found fonts/AvenirLTStd-Black.woff )on android 7.0 devices. I have tested ttf and otf fonts on android 7.0 devices and it is working fine. Only woff fonts gives this exception.

I have attached the screen shot also which shows the fonts in assests/fonts folder. asset folder with woff fonts

Can anyone help me" what is the issue here?

Thanks in advance Krishna


回答1:


WOFF support in Android 7.0 and 7.1 appears to be at least partially broken, with such fonts being unloadable from package assets directories. Your best option, if you are supporting Nougat, is to get TTF or OTF versions of your fonts and use those instead.



来源:https://stackoverflow.com/questions/42342572/android-runtime-exception-font-asset-not-found-for-woff-font-files-in-android

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!