具有多种文本颜色的文本视图android

发布于 2025-01-05 05:50:59 字数 123 浏览 3 评论 0原文

我想在单个文本视图中显示前“RedBlueGray”的字符串,例如红色应以红色字体颜色显示,蓝色应以蓝色字体显示,灰色应以灰色字体显示。这可能吗?如果是这样,实现的最佳方法是什么。请注意,我要显示的字符串会动态变化,但颜色不会变化。

I want to show a string for ex "RedBlueGray" in a single text view like Red should appear with red font color, Blue with blue font and Gray with Gray font.Is it possible? if so, What is the best way to achieve. Note the string I want to display will change dynamically but not colors.

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

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

发布评论

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

评论(3

酷炫老祖宗 2025-01-12 05:50:59

您可以使用如下所示的内容:

actualStringToDisplay="<font COLOR=\"RED\"><b>" + yourString + "</b></font>";

textDisplayedBottom.setText(Html.fromHtml(actualStringToDisplay));

希望这会有所帮助。

You can use something like below for this :

actualStringToDisplay="<font COLOR=\"RED\"><b>" + yourString + "</b></font>";

textDisplayedBottom.setText(Html.fromHtml(actualStringToDisplay));

Hope this helps.

橙幽之幻 2025-01-12 05:50:59

最简单的方法是定义一个 html 字符串:

String text="<FONT COLOR="#RED">red</FONT><FONT COLOR="#GREEN">green</FONT><FONT COLOR="#BLUE">blue/FONT>";

将此字符串设置为 textView

TextView.setText(Html.fromHtml(text));

Simplest way to do this define a html string:

String text="<FONT COLOR="#RED">red</FONT><FONT COLOR="#GREEN">green</FONT><FONT COLOR="#BLUE">blue/FONT>";

set this string to textView by

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