Android 2.1 中无法加载外部字体
我在嵌入的 HTML 资源中使用外部 TrueType 字体。字体位于资源中,与 HTML 资源处于同一级别。
字体使用 CSS 加载:
@font-face {
font-family: MyExternalFont;
src: url('MyExternalFont.ttf');
}
body {
font-family:MyExternalFont;
}
HTML 资源加载如下:
WebView w = (WebView) findViewById(R.id.webview);
w.loadUrl("file:///android_asset/index.htm");
这在 Android 1.5、Android 1.6 和 Android 2.2 中运行良好。它在Android 2.1中不起作用。
但是,当我加载字体并在 TextView
中使用它时,它适用于所有 Android 版本。我这样做:
final Typeface t = Typeface.createFromAsset(getContext().getAssets(), "MyExternalFont.ttf");
textView.setTypeface(t);
可能是什么问题?
(不幸的是我无法上传字体,因为它是付费字体)
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)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
这是 Android 2.0 和 2.1 的已知错误。抱歉,您无法在平台上的 WebView 中使用外部字体。
That's known bug for android 2.0 and 2.1. You can't use external fonts in WebView on the platforms, sorry.