Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

After calling setTextColor, text does not appear in TextView

Tags:

android

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?

like image 340
Adam Driscoll Avatar asked Dec 09 '10 04:12

Adam Driscoll


1 Answers

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"
like image 107
Paresh Mayani Avatar answered Sep 27 '22 23:09

Paresh Mayani