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"/>
zataar
  • 199
  • 1
  • 1
  • 7
  • 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. – zataar Feb 26 '12 at 06:21

1 Answers1

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.

Community
  • 1
  • 1
Code Poet
  • 11,227
  • 19
  • 64
  • 97