文本视图中的富文本 [英] Rich text in a textview

查看:33
本文介绍了文本视图中的富文本的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要创建一个信息";对于我的程序.我想用几种颜色、样式、字体等填充信息文本.

I need to create an "Info" for my program. I'd like to fill the info text with several colors, style, fonts, etc.

我找到了这个链接 用一种方法来实现它.

I found this link with a way how to achieve it.

还有其他方法(更好或更简单)吗?

Is there any other way (better or easier) to do this?

推荐答案

在阅读了您的问题标题后,我准备为您提供指向该文章的链接.我发现使用 spans 和 SpannableString 非常强大.另一种方法是对您的文本使用 HTML 格式,这可以通过 Html.fromHtml().

Upon reading your question title, I was prepared to give you a link to that exact article. I've found using spans and SpannableString to be quite powerful. The alternate would be to use HTML formatting for your text, which can be done with Html.fromHtml().

但是,目前尚不清楚支持哪些 HTML 标记,因为文档中的内容只是:

However, It's not exactly clear which HTML tags are supported, since the documentation simply reads:

该类将 HTML 字符串处理为可显示的样式文本.不是支持所有 HTML 标签.

This class processes HTML strings into displayable styled text. Not all HTML tags are supported.

所以,对于一个好的解决方案,我肯定会使用文章中的 SpannableString 方法.这种方法在实践中非常方便,因为您还可以创建自己的 span 类来扩展现有的类(例如,如果您想让一段文本使用未内置的自定义字体).

So, for a good solution, I would definitely go with the SpannableString approach in the article. This method is very handy in practice since you can also make your own span classes that extend the existing ones (for example, if you want to have a section of text use a custom font that isn't built in).

这篇关于文本视图中的富文本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆