【发布时间】:2015-11-24 12:15:35
【问题描述】:
【问题讨论】:
-
像这样:stackoverflow.com/questions/4897349/… PS:你可以在那里改变颜色或任何你想要的东西。你应该多谷歌一下。
-
你得到答案了吗?
标签: android
【问题讨论】:
标签: android
尝试将HTML字符串设置为TextView
String text = "831<sup>69</sup>";
textView.setText(Html.fromHtml(text), TextView.BufferType.SPANNABLE);
【讨论】:
这是在 java 文件中执行此操作的一种方法:
textview.setText(Html.fromHtml("<b>" + title + "</b>" + "<small>" + description + "</small>"));
或
使用spans。
例子:
final SpannableStringBuilder sb = new SpannableStringBuilder("your text here");
// Span to set text color to some RGB value
final ForegroundColorSpan fcs = new ForegroundColorSpan(Color.rgb(158, 158, 158));
// Span to make text bold
final StyleSpan bss = new StyleSpan(android.graphics.Typeface.BOLD);
// Set the text color for first 4 characters
sb.setSpan(fcs, 0, 4, Spannable.SPAN_INCLUSIVE_INCLUSIVE);
// make them also bold
sb.setSpan(bss, 0, 4, Spannable.SPAN_INCLUSIVE_INCLUSIVE);
yourTextView.setText(sb);
【讨论】: