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>其它顏色"));