I am working on an Android project using Eclipse. I want to change the background color of a TextView using one of the colors I\'ve defined in res/values/colors.xml. These c
Actually it's even easier with this:
weight2.setBackgroundResource(R.color.darkgrey);
It isn't working because you're setting the background color to the key itself (which is an hexadecimal value like 0x7f050008
) instead of its value. To use it's value, try:
weight2.setBackgroundColor(getResources().getColor(R.color.darkgrey));