Android TextView 部分字符高亮

方法一 :

String str="imp"; 
textView.setText(Html.fromHtml("<font color=\"#ff0000\">"+str));

方法二 :

SpannableStringBuilder styled = new SpannableStringBuilder(textView.getText());

// i 未起始字符索引,j 为结束字符索引
styled.setSpan(new ForegroundColorSpan(Color.RED), i, j,Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);

textView.setText(styled);

方法三 :

textView.setText(Html.fromHtml("<font color=\"#ff0000\">红色</font>其它颜色"));

 

 

 

相关文章:

  • 2021-06-02
  • 2021-12-01
  • 2021-07-18
  • 2021-12-24
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
猜你喜欢
  • 2022-12-23
  • 2021-12-23
  • 2021-06-17
  • 2021-09-30
  • 2022-12-23
  • 2022-12-23
相关资源
相似解决方案