wufoo
wufoo

Reputation: 14571

Android XML Color shows up as gray?

I'm trying to use Paint.setColor() with a color from res/values/colors.xml but it keeps coming out "grayish". If I use a string literal instead and use Paint.parseColor() it shows up correctly. What's going on?

onDraw()

p.setColor (Color.parseColor ("#82ef82")); // <- this works
p.setColor (R.color.PeaGreen); // <- this is gray

colors.xml

<color name="PeaGreen">#82ef82</color>

Upvotes: 1

Views: 458

Answers (1)

Samuel
Samuel

Reputation: 17171

R.color.PeaGreen is not a color, it's a resource id for a color resource. But since colors are represented by integers and so are resource id's, it's not throwing any warning or error. You need to do a little bit of work to get the actual color from a resource id:

p.setColor(context.getResources().getColor(R.color.PeaGreen));

There are also a few color constants defined in the Color class and you can use them like so:

p.setColor(Color.RED);

Upvotes: 2

Related Questions