Niall
Niall

Reputation: 1621

Custom color not available

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

Answers (2)

Sunny
Sunny

Reputation: 219

Remove the import of android.R and then build again.

Upvotes: 4

Nambi
Nambi

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

Related Questions