From 45b99f603e377e978d7a73cdfee10b50ed83ff43 Mon Sep 17 00:00:00 2001 From: conradchen Date: Mon, 18 Apr 2022 20:47:22 -0400 Subject: [PATCH] [Button] Fix the issue that button state is not updated On Lollipop, when first assigned as View's background, RippleDrawable won't/can't propagate states to its content drawable. This causes the issue that the state relevant features like stroke colors are not correctly updated when the background is recreated. Explicitly assigns states to the content drawable to fix the issue. Resolves https://github.com/material-components/material-components-android/issues/1422 PiperOrigin-RevId: 442676637 --- .../google/android/material/button/MaterialButtonHelper.java | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/lib/java/com/google/android/material/button/MaterialButtonHelper.java b/lib/java/com/google/android/material/button/MaterialButtonHelper.java index d2ffee3ffa3..fd5e5c304dc 100644 --- a/lib/java/com/google/android/material/button/MaterialButtonHelper.java +++ b/lib/java/com/google/android/material/button/MaterialButtonHelper.java @@ -143,6 +143,11 @@ private void updateBackground() { MaterialShapeDrawable materialShapeDrawable = getMaterialShapeDrawable(); if (materialShapeDrawable != null) { materialShapeDrawable.setElevation(elevation); + if (IS_LOLLIPOP) { + // Fix the issue that on Lollipop, when first assigned as View's background, RippleDrawable + // won't/can't propagate states to its content drawable. (It somehow works afterwards.) + materialShapeDrawable.setState(materialButton.getDrawableState()); + } } }