6

I have a custom cursor adapter and I am trying to set the color of a text box of one of the row views:

 txtChange.setTextColor(0xE01B4C);
 txtChange.setText("Hey I'm some Text!");

If I remove the setTextColor call the text appears as expected. What am I missing?

Adam Driscoll
  • 9,395
  • 9
  • 61
  • 104

1 Answers1

8

A color value specifies an RGB value with an alpha channel, which can be used in various places such as specifying a solid color for a Drawable or the color to use for text. It always begins with a # character and then is followed by the alpha-red-green-blue information in one of the following formats: #RGB, #ARGB, #RRGGBB or #AARRGGBB.

So do one thing define your color inside the color.xml file as:

<color name="demo_color">#E01B4C</color>

And then access it as below:

 txtChange.setTextColor(R.color.demo_color);

Or

you can also define in the XML layout file itself:

android:textColor="#E01B4C"
Community
  • 1
  • 1
Paresh Mayani
  • 127,700
  • 71
  • 241
  • 295
  • 8
    Thanks. Got me headed in the right direction. The way I actually got it to work was: txtChange.setTextColor(getResources.getColor(R.color.demo_color)) – Adam Driscoll Dec 09 '10 at 23:52
  • @Adam glad about your reply !! and the way you mentioned that is also valid. – Paresh Mayani Dec 10 '10 at 04:43
  • 2
    @Adam: The getResources part is a method so it should be getResources(). See this question: http://stackoverflow.com/questions/6177273/textview-settextcolor-not-working – styfle Nov 26 '11 at 01:18