Reputation: 1621
I am trying to add a custom Color to my project, but for some reason it is not appearing in R.color
. I have added a colors.xml
file as follows
<?xml version="1.0" encoding="utf-8"?>
<resources>
<color name="bronze">#ffc125</color>
</resources>
and now when I try to use the new colour as follows
paint.setColor(getResources().getColor(R.color.bronze));
I get a compile error as bronze does not appear in the list. I've tried moving the definition to styles.xml but it still doesn't appear. I've also tried cleaning the project to force R to rebuild but it didn't make any difference either. Can anyone see what I'm doing wrong here?
Thanks
Upvotes: 1
Views: 59
Reputation: 12040
getColor()
returns int so set to the view you need to use the color
resource xml
<?xml version="1.0" encoding="utf-8"?>
<resources>
<color name="bronze">#8C7853</color>
</resources>
setColor to the view,here i used in textview
textView.setTextColor(getResources().getColor(R.color.errorColor));
Upvotes: 0