Android - TextView with different background colors
1 answer
Yes.
SpannableString spannableString = new SpannableString(getString(R.string.hello_world));
Object greenSpan = new BackgroundColorSpan(Color.GREEN);
Object redSpan = new BackgroundColorSpan(Color.RED);
spannableString.setSpan(greenSpan, 0, 6, 0);
spannableString.setSpan(redSpan, 6, spannableString.length(), 0);
TextView textView = (TextView) findViewById(R.id.text);
textView.setText(spannableString);
Outputs:
EDIT: There are many different types of spunning, you can do much nicer things than my main example. Check out this article.
+11
source to share