使用 Html.fromHtml 设置自定义 Typeface

发布于 2024-10-05 08:28:37 字数 292 浏览 0 评论 0原文

我发现 HTML.fromHtml 支持(据说)支持创建跨文本的 HTML 标签列表:

http://commonsware.com/blog/Android/2010/05/26/html-tags-supported-by-textview.html

现在有什么方法可以使用字体标签设置自定义字体吗?

I found this list of HTML-Tags that are (supposedly) supported for HTML.fromHtml to create a Spanned-Text:

http://commonsware.com/blog/Android/2010/05/26/html-tags-supported-by-textview.html

Now is there ANY way to set a custom Typeface with the Font-Tag?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

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

发布评论

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

评论(2

你的呼吸 2024-10-12 08:28:37

只需使用带有 face 属性的 标签即可。至少从 Android 1.5 开始(查看源代码)。

face 属性的值将传递给 TypefaceSpan (字符串) 构造函数 用于创建 Spannable。例如,使用“等宽字体”、“衬线字体”或“无衬线字体”。

Simply use a <font> tag with a face attribute. This has been possible since at least Android 1.5 (see source code).

The value of the face attribute will be passed to the TypefaceSpan(String) constructor to create the Spannable. For example, use "monospace", "serif", or "sans-serif".

满身野味 2024-10-12 08:28:37

过时了。查看其他答案。


不,没有办法这样做。您可以 看一下 Html 实现。正如您将看到的,font 标记仅支持sizecolor

Outdated. See other answers.


No, there's no way to do so. You can take a look at the Html implementation. As you will see, the font tag supports size and color only.

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