23 January 2012

How to set text Color in Android correctly?

Common mistake which I made when  start developing application for Android was attempt to set text color  in this way:
pornName.setTextColor(R.color.period_red );
which didn't display anything or it was  incorrect color .
To use resource from xml files you need use   getResources()  method .So for color in this case will be:

where period_red you set in

  <color name="red">#ff0000</color>
  I hope it helps.