2

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

Krishna
  • 71
  • 3

1 Answers1

2

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.

Chris Charabaruk
  • 4,367
  • 2
  • 30
  • 57
  • Hi Chris, do you know of any bugs on google that is already tracking this? I'm noticing this as well. – b.lyte Jun 21 '17 at 00:01
  • @clu unfortunately no. I only found out about this by searching for answers myself. I wish I had added the source I found to the answer, because I can't find it in my browser history anymore. :( – Chris Charabaruk Jun 21 '17 at 23:42