Invalidate when Drawable.setState() returns true
Ensures views that manage drawables follow the contract set forth in
the Drawable.setState() documentation.
Bug: 23792020
Change-Id: I4e5a449cd6535487873fd8443da50555c38e8ed9
diff --git a/core/java/android/widget/CompoundButton.java b/core/java/android/widget/CompoundButton.java
index 602e1ab..b19fe17 100644
--- a/core/java/android/widget/CompoundButton.java
+++ b/core/java/android/widget/CompoundButton.java
@@ -456,14 +456,11 @@
@Override
protected void drawableStateChanged() {
super.drawableStateChanged();
-
- if (mButtonDrawable != null) {
- int[] myDrawableState = getDrawableState();
-
- // Set the state of the Drawable
- mButtonDrawable.setState(myDrawableState);
-
- invalidate();
+
+ final Drawable buttonDrawable = mButtonDrawable;
+ if (buttonDrawable != null && buttonDrawable.isStateful()
+ && buttonDrawable.setState(getDrawableState())) {
+ invalidateDrawable(buttonDrawable);
}
}