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.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With