我想在显示到 TextView 之前更改文本颜色。
例如,
我正在从服务器获取文本
<b>Pratik<b/> has shared photo with <b>you</b>.
现在要求显示Pratik
和 you
使用粗体样式和蓝色文本颜色。我尝试了几种使用 <span>
的方法标签,但我没有找到显示它的明确方法。
String htmlBody = "<b>Pratik<b/> has shared photo with <b>you</b>.";
String formattedBody = "<span>" + htmlBody + "</span><style>b { color: #309ce8 ; } span {font-family: 'Avenir', 'Heavy'; font-size: 17; }</style>";
SpannableString text = new SpannableString(formattedBody);
tvMessage.setText(text, TextView.BufferType.SPANNABLE); // This is not working as expected.
tvMessage.setText(Html.fromHtml(htmlBody)); // This is not working as expected.
帮助我实现这一目标。
最佳答案
String htmlBody = "<b style='color:blue !important;'>Pratik</b> has shared photo with <b style='color:blue !important;'>you</b>.";
关于android - 更改粗体 html 文本的文本颜色,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47587075/