3

Is it possible to change the color of some of the characters in a string in Android? For example change the color of the letters d and r in the word android to green.

<TextView android:id="@+id/word" android:gravity="center_vertical" android:typeface="monospace" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="" android:textSize="30pt"/> 
1
  • I'm just using the XML TextView such the one I inserted above in the main question. I display the text in the main code using word.setText("Android") but I need to change some of the characters to different colors. Commented Feb 26, 2012 at 6:21

1 Answer 1

2

You could initialize the TextView with html instead of plain text. The html could define the text spans with colors. See Set TextView text from html-formatted string resource in XML for how.

In case you don't want to use html you can use SpannableString.

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.