如何更改EditText中单个单词的颜色?也就是说,所有单词都是同一种颜色,而一个单独的单词则是另一种颜色。
敬礼
如何更改EditText中单个单词的颜色?也就是说,所有单词都是同一种颜色,而一个单独的单词则是另一种颜色。
敬礼
SpannableStringBuilder ssb = new SpannableStringBuilder(yourText);
ForegroundColorSpan colorSpan = new ForegroundColorSpan(
context.getResources()
// Specify your color
.getColor(R.color.your_font_color));
realPrice.setSpan(colorSpan,
0, // Start index of the single word
1, // End index of the single word
Spanned.SPAN_EXCLUSIVE_INCLUSIVE);
yourEditText.setText(ssb);
String text = "<font color=#0000ff>sample</font> <font color=#ff0000>text</font>";
edittext.setText(Html.fromHtml(text));
SpannableString
。 - AndyN