Johan Johan - 4 months ago 58
Android Question

Change drawable color programmatically

I'm trying to change the color on a white marker image by code. I have read that the code below should change the color, but my marker remains white.

Drawable.setColorFilter( 0xffff0000, Mode.MULTIPLY )


Did I miss something? Is there any other way to change colors on my drawables located in my res folder?

Answer

try this:

Drawable mDrawable = context.getResources().getDrawable(R.drawable.balloons); 
mDrawable.setColorFilter(new 
PorterDuffColorFilter(0xffff00,PorterDuff.Mode.MULTIPLY));
Comments