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

后端 未结 2 856
长发绾君心
长发绾君心 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: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));
    

提交回复
热议问题