Android 2.1 中无法加载外部字体

发布于 2024-10-02 12:31:14 字数 789 浏览 1 评论 0原文

我在嵌入的 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.5Android 1.6Android 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

玩世 2024-10-09 12:31:14

这是 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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文