2 different colors for Text in same text view in android

user2115214 picture user2115214 · Feb 27, 2013 · Viewed 23.5k times · Source

I have a TextView widget, as shown below

<TextView 
        android:text="@string/inputText"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_weight="1" />

The inputText is defined in Strings.xml as

<String name="inputText">The value of input is positive now</String>

Now, I want the whole text to be displayed in Brown color, and only 'positive' in green color.

Is there any way to do so ? in brief my question is multiple coloring for same textview at the same time

Answer

M4tchB0X3r picture M4tchB0X3r · Feb 27, 2013

this is a dublicate of this question Change text color of one word in a TextView.

String first = "This word is ";
String next = "<font color='#EE0000'>red</font>";
t.setText(Html.fromHtml(first + next));