android - 更改粗体 html 文本的文本颜色

标签 android html textview foreground

我想在显示到 TextView 之前更改文本颜色。

例如,
我正在从服务器获取文本

<b>Pratik<b/> has shared photo with <b>you</b>.

现在要求显示Pratikyou使用粗体样式和蓝色文本颜色。我尝试了几种使用 <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/

相关文章:

android - 加载时检查 RecyclerView 中的 CheckBox

html - 使 div 围绕移动的 div 运行

html - CSS所有div与直接子div

android - 动态添加到表行时 ImageButton 不可见

android - 在 ImageView 的角上显示文本

ios - 如何在 Swift3 中更改 UITextView 中文本字符串的颜色

android - 在 adb logcat 输出中格式化 json 字符串

java - 安卓软键盘大小

javascript - 如何在一行中保持 float ul 元素

android - bin 目录中的 AndroidManifest.xml 是否重复?