How to change a TextView's background color with a color defined in my values/colors.xml file?

后端 未结 2 834
长发绾君心
长发绾君心 2021-01-05 18:24

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

相关标签:
2条回答
  • 2021-01-05 18:29

    Actually it's even easier with this:

    weight2.setBackgroundResource(R.color.darkgrey);
    
    0 讨论(0)
  • 2021-01-05 18:51

    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));
    
    0 讨论(0)
提交回复
热议问题