zataar
zataar

Reputation: 199

Android string colors

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"/>

Upvotes: 3

Views: 838

Answers (1)

Code Poet
Code Poet

Reputation: 11437

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.

Upvotes: 2

Related Questions