'Android change the color of AnimationDrawable

So I have a confetti animation, and I want to change the color of the confetti dynamically. Is this possible? I've tried setting a color filter on both the Animation Drawable and the Drawables for the individual frames. I have also tried setting the tint of the AnimationDrawable and the individual frames, but not getting any success. I get white confetti every time.

Drawable d1 = ContextCompat.getDrawable(getActivity(), R.drawable.white_confetti1); //The frames of the animation drawable.
Drawable d2 = ContextCompat.getDrawable(getActivity(), R.drawable.white_confetti2);

int green = Color.parseColor("#1adb20"); //change the color to green.

d1.setTint(green); //green when using directly, but not when loaded into AnimationDrawable d
d2.setTint(green);

d1.mutate().setColorFilter(green, PorterDuff.Mode.MULTIPLY); //this doesn't seem to work either.
d2.mutate().setColorFilter(green, PorterDuff.Mode.MULTIPLY);

AnimationDrawable d = new AnimationDrawable();
d.addFrame(d1, 120);
d.addFrame(d2, 120);

d.mutate().setColorFilter(green, PorterDuff.Mode.MULTIPLY); //this doesn't change anything.
d.setTint(green); //neither does this.

p2 = new ParticleSystem(getActivity(), 100, d, 10000, R.id.confetti_window)
        .setSpeedModuleAndAngleRange(0f, 0.15f, 0, 0)
        .setRotationSpeed(154)
        .setAcceleration(0.00008f, 90);
p2.emit(0, 0, 8);


Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source