diff --git a/api/current.xml b/api/current.xml
index 13b708c8078a7..afe86fb5713bc 100644
--- a/api/current.xml
+++ b/api/current.xml
@@ -6697,6 +6697,17 @@
visibility="public"
>
+
+
+
+
+
+
-
@@ -2943,6 +2942,14 @@
+
+
+
+
+
+
+
+
diff --git a/core/res/res/values/public.xml b/core/res/res/values/public.xml
index b0be7e1402c76..e319fa0db25d7 100644
--- a/core/res/res/values/public.xml
+++ b/core/res/res/values/public.xml
@@ -1378,6 +1378,7 @@
+
diff --git a/graphics/java/android/graphics/drawable/LayerDrawable.java b/graphics/java/android/graphics/drawable/LayerDrawable.java
index b6cce7ef50069..09c041f7a0025 100644
--- a/graphics/java/android/graphics/drawable/LayerDrawable.java
+++ b/graphics/java/android/graphics/drawable/LayerDrawable.java
@@ -26,6 +26,7 @@ import android.graphics.ColorFilter;
import android.graphics.PixelFormat;
import android.graphics.Rect;
import android.util.AttributeSet;
+import android.util.Slog;
import android.view.View;
import java.io.IOException;
@@ -49,6 +50,7 @@ import java.io.IOException;
public class LayerDrawable extends Drawable implements Drawable.Callback {
LayerState mLayerState;
+ private int mOpacityOverride = PixelFormat.UNKNOWN;
private int[] mPaddingL;
private int[] mPaddingT;
private int[] mPaddingR;
@@ -113,6 +115,13 @@ public class LayerDrawable extends Drawable implements Drawable.Callback {
int type;
+ TypedArray a = r.obtainAttributes(attrs, com.android.internal.R.styleable.LayerDrawable);
+
+ mOpacityOverride = a.getInt(com.android.internal.R.styleable.LayerDrawable_opacity,
+ PixelFormat.UNKNOWN);
+
+ a.recycle();
+
final int innerDepth = parser.getDepth() + 1;
int depth;
while ((type = parser.next()) != XmlPullParser.END_DOCUMENT
@@ -125,7 +134,7 @@ public class LayerDrawable extends Drawable implements Drawable.Callback {
continue;
}
- TypedArray a = r.obtainAttributes(attrs,
+ a = r.obtainAttributes(attrs,
com.android.internal.R.styleable.LayerDrawableItem);
int left = a.getDimensionPixelOffset(
@@ -391,9 +400,28 @@ public class LayerDrawable extends Drawable implements Drawable.Callback {
array[i].mDrawable.setColorFilter(cf);
}
}
+
+ /**
+ * Sets the opacity of this drawable directly, instead of collecting the states from
+ * the layers
+ *
+ * @param opacity The opacity to use, or {@link PixelFormat#UNKNOWN PixelFormat.UNKNOWN}
+ * for the default behavior
+ *
+ * @see PixelFormat#UNKNOWN
+ * @see PixelFormat#TRANSLUCENT
+ * @see PixelFormat#TRANSPARENT
+ * @see PixelFormat#OPAQUE
+ */
+ public void setOpacity(int opacity) {
+ mOpacityOverride = opacity;
+ }
@Override
public int getOpacity() {
+ if (mOpacityOverride != PixelFormat.UNKNOWN) {
+ return mOpacityOverride;
+ }
return mLayerState.getOpacity();
}