Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Issue in loading custom fonts in Android 4.2 (API 17)

I have a static html file "myhtml.html" stored in my assets/html/ directory and this html loads custom font (stored under assets/fonts/) as follows:

<style type="text/css">
    @font-face {
        font-family: 'MyFont';
        src: url('file:///android_asset/fonts/myfont.ttf');
    }
</style>

I am loading this html using the following code:

String html = getHtml(); // This method loads the myhtml.html from asset. This loads properly.
WebView webView = (WebView) findViewById(R.id.webbox);
WebSettings webSettings = webView.getSettings(); 
webSettings.setDefaultTextEncodingName("utf-8");
webSettings.setFixedFontFamily("fonts/myfont.ttf");
webView.loadDataWithBaseURL("file:///android_asset/", html, "text/html", "UTF-8", null);

This code works fine all the android versions except Android 4.2 (API 17).

In Android 4.2, the HTML is loaded but the custom font is not loaded.

like image 791
yottabrain Avatar asked Mar 04 '13 07:03

yottabrain


1 Answers

I think that this is a bug. I filed https://code.google.com/p/android/issues/detail?id=54516

If anyone knows differently, please correct me. Also, if this bug bothers you, please star it to get more attention.

like image 61
Christopher Avatar answered Oct 25 '22 02:10

Christopher