Commit babac434 authored by Evan W. Patton's avatar Evan W. Patton Committed by Jeffrey Schiller

Fix NPE when copying button background on SDK 7

Change-Id: I20f1e3b8b302674e44ea92893e0eb395b9813856
parent 64c2601a
......@@ -423,8 +423,15 @@ public abstract class ButtonBase extends AndroidViewComponent
private Drawable getSafeBackgroundDrawable() {
if (myBackgroundDrawable == null) {
Drawable.ConstantState state = defaultButtonDrawable.getConstantState();
if (state != null) {
if (state != null && Build.VERSION.SDK_INT >= Build.VERSION_CODES.GINGERBREAD_MR1) {
try {
myBackgroundDrawable = state.newDrawable().mutate();
} catch (NullPointerException e) {
// We see this on SDK 7, but given we can't easily test every version
// this is meant as a safeguard.
Log.e(LOG_TAG, "Unable to clone button drawable", e);
myBackgroundDrawable = defaultButtonDrawable;
}
} else {
// Since we can't make a copy of the default we'll just use it directly
myBackgroundDrawable = defaultButtonDrawable;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment