dinesh707
dinesh707

Reputation: 12582

Why R.color.xyz appear "gray", when i use in Canvas?

here is my color.xml

<color name="xyz">#507EC0</color>
<color name="abc">#27B0D0</color>
<color name="def">#A8CBE1</color> 

and here goes the code inside onDraw()

Paint xyzPaint = new Paint();
         thisWeekTotalPaint.setColor(R.color.xyz);
         canvas.drawRect(30, 70, 200, 100, xyzPaint);

But it appears to be gray what ever the color i use.

Upvotes: 0

Views: 83

Answers (1)

Floern
Floern

Reputation: 33904

R.color.xyz contains the Resource ID of the color, not the color itself, which you need for setColor().

So you have to get the color from the Resources first:

int color = getResources().getColor(R.color.xyz);
yourPaint.setColor(color);

Upvotes: 4

Related Questions