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

问题描述

我需要为我的程序中创建一个信息。我想填补信息文本的几种颜色,样式,字体,ECC。

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

我发现这一点:http://www.chrisumbel.com/article/android_textview_rich_text_spannablestring

有另一种方式(更容易)来做到这一点?

is there another way (better easy) to do this?

谢谢!

推荐答案

在阅读你的问题的标题,我ppared给你一个链接到具体的文章$ P $。我使用的跨度发现, 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标签的支持。

因此​​,对于一个很好的解决方案,我肯定会去的文章 SpannableString 办法。这种方法是非常方便的做法,因为你也可以让自己的跨度类,扩展现有的(例如,如果你想拥有一段文字使用不内置自定义字体)。

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).

这篇关于在一个TextView富文本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-02 07:36