diff options
author | Maurice Lam <yukl@google.com> | 2019-03-27 20:57:42 -0700 |
---|---|---|
committer | Maurice Lam <yukl@google.com> | 2019-03-28 11:38:41 -0700 |
commit | 2c49b010bb28fcb7b9c666389308cee98db958a1 (patch) | |
tree | ab76356d91ba9c123b2be69cd472708cbd35ca8d | |
parent | ee2af55d972243d376855d13417c66a17e168674 (diff) | |
download | setupcompat-2c49b010bb28fcb7b9c666389308cee98db958a1.tar.gz |
Force state refresh in button background before setting tint
Test: Manual
Bug: 129414679
Change-Id: If8b068ede2aaefcd9451c9b359156a243775117b
-rw-r--r-- | main/java/com/google/android/setupcompat/template/FooterBarMixin.java | 11 |
1 files changed, 10 insertions, 1 deletions
diff --git a/main/java/com/google/android/setupcompat/template/FooterBarMixin.java b/main/java/com/google/android/setupcompat/template/FooterBarMixin.java index dd3d930..4a52414 100644 --- a/main/java/com/google/android/setupcompat/template/FooterBarMixin.java +++ b/main/java/com/google/android/setupcompat/template/FooterBarMixin.java @@ -507,12 +507,21 @@ public class FooterBarMixin implements Mixin { new ColorStateList( new int[][] {DISABLED_STATE_SET, ENABLED_STATE_SET}, new int[] {convertRgbToArgb(color, alpha), color}); + + // b/129482013: When a LayerDrawable is mutated, a new clone of its children drawables are + // created, but without copying the state from the parent drawable. So even though the parent + // is getting the correct drawable state from the view, the children won't get those states + // until a state change happens. + // As a workaround, we mutate the drawable and forcibly set the state to empty, and then + // refresh the state so the children will have the updated states. + button.getBackground().mutate().setState(new int[0]); + button.refreshDrawableState(); button.setBackgroundTintList(colorStateList); } } private void updateButtonBackground(Button button, @ColorInt int color) { - button.getBackground().setColorFilter(color, Mode.SRC_ATOP); + button.getBackground().mutate().setColorFilter(color, Mode.SRC_ATOP); } private void updateButtonRadiusWithPartnerConfig(Button button) { |