我希望在将文本显示到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.
帮我实现这个目标。
<b>Pratik</b>与<b>你</b>分享了照片。
- ND1010_