Nurul Endah Amelia
Nurul Endah Amelia

Reputation: 31

Android setColor - want to change color but always didn't work

I want to change color to used in the following example to brown, but my attempts are not working:

 mPaint = new Paint();
 mPaint.setAntiAlias(true);
 mPaint.setDither(true);
 mPaint.setColor(Color.RED);

This doesn't work:

mPaint.setColor(Color.Brown);

nor does this:

mPaint.setColor(mPaint.setColor(0x00994C00));

It only works when I change the color to to RED, GREEN, BLUE, CYAN, MAGENTA.

Can someone help me to solve this problem?

Upvotes: 1

Views: 2556

Answers (2)

Grzegorz Żak
Grzegorz Żak

Reputation: 164

Try:

mPaint.setColor(Color.argb(0xff, 0x99, 0x4c, 0x00));

or:

mPaint.setColor(0xff994c00);

Upvotes: 6

rafsanahmad007
rafsanahmad007

Reputation: 23881

Try this

int myColor= getApplicationContext().getResources().getColor(com.package_name.R.color.white);
mPaint.setColor(myColor);

define white color in your color.xml file

Upvotes: 1

Related Questions