Question

I'm using a external TrueType font in an embedded HTML resource. The font is located in assets, at the same level than the HTML resource.

The font is loaded with CSS:

@font-face { 
    font-family: MyExternalFont; 
    src: url('MyExternalFont.ttf'); 
}
body {
    font-family:MyExternalFont;
}

And the HTML resource is loaded as follows:

WebView w = (WebView) findViewById(R.id.webview);
w.loadUrl("file:///android_asset/index.htm");

This works fine in Android 1.5, Android 1.6 and Android 2.2. It doesn't work in Android 2.1.

However, when I load the font and use it in a TextView, it works on all Android versions. I do it like this:

final Typeface t = Typeface.createFromAsset(getContext().getAssets(), "MyExternalFont.ttf");
textView.setTypeface(t);

What might be the problem?

(Unfortunately I can't upload the font because it's a paid font)

Was it helpful?

Solution

That's known bug for android 2.0 and 2.1. You can't use external fonts in WebView on the platforms, sorry.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top