In one application that I am developing, I am trying to programmatically create an ImageButton , which is a copy of the selected ImageButton , but the image is colored differently, say red.
If I use PowerDuff.Mode.MULTIPLY :
clonebutton.getDrawable().setColorFilter(0xFFFF0000,Mode.MULTIPLY);
Then even the original ImageButton changes its color to red, since they have the same drawable . Is there a way to apply a filter only to a clone button without using two different drawables ? For example, is it possible to somehow put a coloring layer on top of a clone button without editing drawable ?
Update I install drawable as mutable:
Drawable d = swipebutton.getDrawable(); d.mutate(); d.setColorFilter(0xFFFF0000,Mode.MULTIPLY); swipebutton.setImageDrawable(d);
This prevents my clone from sharing the state of its drawable with other views .
source share