Skip to content

Commit

Permalink
[Button] Always update drawable state when background changed
Browse files Browse the repository at this point in the history
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
  • Loading branch information
drchen authored and leticiarossi committed May 6, 2022
1 parent 9a16aa4 commit 363e2b1
Showing 1 changed file with 3 additions and 5 deletions.
Expand Up @@ -143,11 +143,9 @@ 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());
}
// Workaround (b/231320562): Setting background will cause drawables wrapped inside a
// RippleDrawable lose their states, we need to reset the state here.
materialShapeDrawable.setState(materialButton.getDrawableState());
}
}

Expand Down

0 comments on commit 363e2b1

Please sign in to comment.