具有多个彩色文本的单个 TextView [英] Single TextView with multiple colored text

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

问题描述

正如标题所说,我想知道是否可以在单个 textview 元素中实现两个不同颜色的字符.

As the title says, I want to know is it possible to achieve two different colored characters in a single textview element.

推荐答案

是的,如果你把 String 格式化成 htmlfont-color 属性然后将其传递给方法 Html.fromHtml(your text here)

yes, if you format the String with html's font-color property then pass it to the method Html.fromHtml(your text here)

String text = "<font color=#cc0029>First Color</font> <font color=#ffcc00>Second Color</font>";
yourtextview.setText(Html.fromHtml(text));

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

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