kriskotoo BG
kriskotoo BG

Reputation: 321

Color part of string in textView in XML

I am trying to display some text in a TextView with @string, the problem is i cant seem to be able to change the color of part of the text. I dont want to use Java to do this as all other questions suggest, since this is the default TextView text.

I've tried using <string name="myString"><font color="#00ff00">My String</font></string> and font fgcolor="#00ff00" but they dont seem to work.

Upvotes: 1

Views: 5463

Answers (2)

Modi Harsh
Modi Harsh

Reputation: 575

I've tried with your given string and it is works for me. Here is an example

  • Create <TextView> inside any layout

    <TextView android:id="@+id/textView" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="@string/text" />

  • Create text string inside strings.xml file

    <string name="text"><font color="#00ff00">Hello</font> <font color="#FF0000">World</font></string>

  • And you can see the result

    enter image description here

Upvotes: 3

sanoJ
sanoJ

Reputation: 3128

Your font color is working for me, Note you have missed the closing tag of the string(the backslash to close the string)

<string name="myString"><font color="#00ff00">My String in green</font> and normal</string>

If this doesn't help, Whats the android version you are testing this

Upvotes: 2

Related Questions