Reputation: 16375
How do you go about changing the color of a single word in a EditText ? Meaning all words will be once color and one single word will be a different color.
Kind Regards
Upvotes: 3
Views: 1306
Reputation: 633
Use ForegroundColorSpan
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);
Upvotes: 3
Reputation: 2609
Try this.
String text = "<font color=#0000ff>sample</font> <font color=#ff0000>text</font>";
edittext.setText(Html.fromHtml(text));
Upvotes: 1