简体   繁体   中英

Colour resource ID returning wrong value

I am trying to set the text colour programatically from a colour resource during onCreate and am getting some wierd results.

I have a colour resource defined in res\\colors.xml:

<resources>

    <color name="wheelFill">#C0FFFFFF</color>

</resources>

my activity then uses the following code to retrieve the colour:

int WheelColour = getResources().getColor(R.color.wheelFill);

Finally I assign it to a Paint:

mBackgroundPaint.setColor(WheelColour);

When I run my application the colour does not get set an I get a log message from the getColor line claiming that "Color value 'List' must start with #". 'List' is the value of one of my string resources so clearly something is getting messed up there.

If I bypass the resource and use:

int WheelColour = Color.argb(0xC0, 0xFF, 0xFF, 0xFF);

Everything works correctly so it has to be the getColor call but I can't see what's wrong with it. (I have tried explicitly using a context which made no difference).

Has anybody else come across this or sucessfully managed to set paint colours from colour resources?

maybe your R.java got messed up and isn't linking to the correct resource. clean the project and refresh

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM