Skip to content

Commit 363e2b1

Browse files
drchenleticiarossi
authored andcommitted
[Button] Always update drawable state when background changed
In certain situations drawable states won't be correctly propagated to the background drawable wrapped in a LayerDrawable during setting view background. Always explicitly updates the drawable state to fix the issue. Resolves #2670 PiperOrigin-RevId: 446786432
1 parent 9a16aa4 commit 363e2b1

File tree

1 file changed

+3
-5
lines changed

1 file changed

+3
-5
lines changed

lib/java/com/google/android/material/button/MaterialButtonHelper.java

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -143,11 +143,9 @@ private void updateBackground() {
143143
MaterialShapeDrawable materialShapeDrawable = getMaterialShapeDrawable();
144144
if (materialShapeDrawable != null) {
145145
materialShapeDrawable.setElevation(elevation);
146-
if (IS_LOLLIPOP) {
147-
// Fix the issue that on Lollipop, when first assigned as View's background, RippleDrawable
148-
// won't/can't propagate states to its content drawable. (It somehow works afterwards.)
149-
materialShapeDrawable.setState(materialButton.getDrawableState());
150-
}
146+
// Workaround (b/231320562): Setting background will cause drawables wrapped inside a
147+
// RippleDrawable lose their states, we need to reset the state here.
148+
materialShapeDrawable.setState(materialButton.getDrawableState());
151149
}
152150
}
153151

0 commit comments

Comments
 (0)