Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Different colors at EditText in Android

I am trying to make the text of an EditText multiple colors. For example, if my text is, "It is a good day.", is it possible to make the "It is a" part of the sentence green and the rest red?

like image 423
Tekin alp Avatar asked Jan 01 '13 20:01

Tekin alp


1 Answers

I use something like that to make some parts of my color green:

final String text = "Some Text";
Spannable modifiedText = new SpannableString(text);
modifiedText.setSpan(new ForegroundColorSpan(getResources().getColor(R.color.green)), 0, lengthYouWant, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
textView.setText(modifiedText);
like image 134
WarrenFaith Avatar answered Oct 10 '22 08:10

WarrenFaith