Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

GradientDrawable setStroke Doesn't Work on Android Lollipop

I have a Drawable inside an image view that I'm modifying at runtime in order to provide custom colors for a user's rank. The method for modifying this works fine on Android versions below 20, but above it the drawable fails to update consistently.

The particular method in question looks like:

void setColor(int color) {
    GradientDrawable drawable = (GradientDrawable) mImageView.getDrawable().mutate();
    drawable.setStroke(14, color);
    drawable.invalidateSelf(); // make sure we redraw
}

As I said, this works fine before Android 20, but after Android 20 the drawable doesn't add the stroke. Is there a new method or did I forget something?

like image 847
Jessica Lohse Avatar asked Jul 30 '26 16:07

Jessica Lohse


1 Answers

you should invalidate the view:

mImageView.invalidate();
like image 55
yossi elazar Avatar answered Aug 02 '26 08:08

yossi elazar



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!