【问题标题】:Android: How to make only one word became bold in TextViewAndroid:如何使 TextView 中只有一个单词变为粗体
【发布时间】:2020-03-22 02:19:47
【问题描述】:

我正在尝试仅使用粗体样式制作一个单词并将其设置在 TextView 中: 我的文字来自一个端点:

"bla bla bla <b>Hello</b> bla"

我试过了,但什么也没发生,Android忽略了标签:

@Override
public void onBindViewHolder(PlanoHolder holder, int position) {
    Spanned x = HtmlCompat.fromHtml(item.getDesc(), HtmlCompat.FROM_HTML_MODE_LEGACY);
    textView.setText(x.toString());
}

【问题讨论】:

    标签: android android-studio android-layout android-fragments


    【解决方案1】:

    这是因为x 再次转换toString。只需传递Spanned 如下

    Spanned x = HtmlCompat.fromHtml(item.getDesc(), HtmlCompat.FROM_HTML_MODE_LEGACY);
    textView.setText(x);
    

    【讨论】:

      猜你喜欢
      • 2020-05-08
      • 2014-09-04
      • 2023-03-20
      • 2010-11-16
      • 2015-08-17
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-12-18
      相关资源
      最近更新 更多