@@ -276,15 +276,9 @@ && isButtonDrawableLegacy(attributes)) {
276
276
277
277
refreshButtonDrawable ();
278
278
279
- // This is needed due to a KitKat bug where the drawable states don't get updated correctly
280
- // in time.
281
- if (VERSION .SDK_INT < VERSION_CODES .LOLLIPOP ) {
282
- post (
283
- () -> {
284
- if (buttonIconDrawable != null ) {
285
- buttonIconDrawable .invalidateSelf ();
286
- }
287
- });
279
+ // This is needed due to a pre-21 bug where the drawable states don't get updated correctly.
280
+ if (VERSION .SDK_INT < VERSION_CODES .LOLLIPOP && buttonIconDrawable != null ) {
281
+ post (() -> buttonIconDrawable .jumpToCurrentState ());
288
282
}
289
283
}
290
284
@@ -338,13 +332,17 @@ protected int[] onCreateDrawableState(int extraSpace) {
338
332
339
333
currentStateChecked = DrawableUtils .getCheckedState (drawableStates );
340
334
341
- if (VERSION .SDK_INT < VERSION_CODES .LOLLIPOP ) {
342
- jumpDrawablesToCurrentState ();
343
- }
335
+ updateIconTintIfNeeded ();
344
336
345
337
return drawableStates ;
346
338
}
347
339
340
+ @ Override
341
+ public void setEnabled (boolean enabled ) {
342
+ super .setEnabled (enabled );
343
+ updateIconTintIfNeeded ();
344
+ }
345
+
348
346
@ Override
349
347
public void setChecked (boolean checked ) {
350
348
setCheckedState (checked ? STATE_CHECKED : STATE_UNCHECKED );
@@ -468,7 +466,6 @@ public void setErrorShown(boolean errorShown) {
468
466
}
469
467
this .errorShown = errorShown ;
470
468
refreshDrawableState ();
471
- jumpDrawablesToCurrentState ();
472
469
for (OnErrorChangedListener listener : onErrorChangedListeners ) {
473
470
listener .onErrorChanged (this , this .errorShown );
474
471
}
@@ -735,14 +732,6 @@ private void refreshButtonDrawable() {
735
732
refreshDrawableState ();
736
733
}
737
734
738
- @ Override
739
- public void jumpDrawablesToCurrentState () {
740
- super .jumpDrawablesToCurrentState ();
741
- if (buttonIconDrawable != null ) {
742
- buttonIconDrawable .jumpToCurrentState ();
743
- }
744
- }
745
-
746
735
/**
747
736
* Set the transition animation from checked to unchecked programmatically so that we can control
748
737
* the color change between states.
@@ -782,6 +771,19 @@ private void updateButtonTints() {
782
771
}
783
772
}
784
773
774
+ /*
775
+ * Update the icon tint due to a pre-21 bug where the drawable states don't get updated correctly.
776
+ */
777
+ private void updateIconTintIfNeeded () {
778
+ if (VERSION .SDK_INT < VERSION_CODES .LOLLIPOP
779
+ && buttonIconDrawable != null
780
+ && buttonIconTintList != null ) {
781
+ buttonIconDrawable .setColorFilter (
782
+ DrawableUtils .updateTintFilter (
783
+ buttonIconDrawable , buttonIconTintList , buttonIconTintMode ));
784
+ }
785
+ }
786
+
785
787
@ RequiresApi (VERSION_CODES .R )
786
788
@ Override
787
789
public void setStateDescription (@ Nullable CharSequence stateDescription ) {
0 commit comments