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:
pornName.setTextColor((getResources().getColor(R.color.period_red)));


where period_red you set in
/mySecretProject/res/values/colors.xml


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