From 62aa802f6c5f45ee357537079b07442dabc31236 Mon Sep 17 00:00:00 2001 From: leticiars Date: Tue, 28 Mar 2023 18:38:12 +0000 Subject: [PATCH] [Checkbox] Fixed checkmark icon not updating color on error correctly in pre 21. Issue happened on checkboxes that switched from unchecked to checked and later to be on error state. Fixes https://github.com/material-components/material-components-android/issues/3302 PiperOrigin-RevId: 520088272 --- .../google/android/material/checkbox/MaterialCheckBox.java | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/lib/java/com/google/android/material/checkbox/MaterialCheckBox.java b/lib/java/com/google/android/material/checkbox/MaterialCheckBox.java index 4e44ff28f10..d48db00688b 100644 --- a/lib/java/com/google/android/material/checkbox/MaterialCheckBox.java +++ b/lib/java/com/google/android/material/checkbox/MaterialCheckBox.java @@ -471,6 +471,10 @@ public void setErrorShown(boolean errorShown) { } this.errorShown = errorShown; refreshDrawableState(); + // This is needed due to a pre-21 bug where the drawable states don't get updated correctly. + if (VERSION.SDK_INT < VERSION_CODES.LOLLIPOP && buttonIconDrawable != null) { + buttonIconDrawable.jumpToCurrentState(); + } for (OnErrorChangedListener listener : onErrorChangedListeners) { listener.onErrorChanged(this, this.errorShown); }