具有多种文本颜色的文本视图android
我想在单个文本视图中显示前“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 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
您可以使用如下所示的内容:
希望这会有所帮助。
You can use something like below for this :
Hope this helps.
最简单的方法是定义一个 html 字符串:
将此字符串设置为 textView
Simplest way to do this define a html string:
set this string to textView by
请参阅 SpannedString & SpannedStringBuilder & ColorSpan
http://developer.android.com/reference/android/text/ style/ForegroundColorSpan.html
http://developer.android.com/reference/android/text/SpannedString.html
See SpannedString & SpannedStringBuilder & ColorSpan
http://developer.android.com/reference/android/text/style/ForegroundColorSpan.html
http://developer.android.com/reference/android/text/SpannedString.html