Android RunTime exception “Font asset not found” f

2019-05-21 11:55发布

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条回答
可以哭但决不认输i
2楼-- · 2019-05-21 12:26

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.

查看更多
登录 后发表回答