android:opacity supports only translucent|opaque|transparent values in layer-list.
By the way what is your requirement?
Updated-Answer: To set opacity/less-visible as 80%, you need to set to your view
android:alpha="0.8"
Question
I want my LayerList to have an opacity of 80 so I wrote:
<layer-list
xmlns:android="http://schemas.android.com/apk/res/android"
android:opacity="80">
But I get:
Error: Integer types not allowed (at 'opacity' with value '80')
How can I specify the opacity?
Solution
android:opacity supports only translucent|opaque|transparent values in layer-list.
By the way what is your requirement?
Updated-Answer: To set opacity/less-visible as 80%, you need to set to your view
android:alpha="0.8"
OTHER TIPS
To give a translucent effect, say 50% opacity, use:
Drawable d = new ColorDrawable(Color.BLACK);
d.setAlpha(130);
mDialog.getWindow().setBackgroundDrawable(d);
'130' can be changed (0-255) to acheive desired opacity.
I think the question asks about setting the opacity of individual items inside a <layer-list>
, and not the whole image programmatically.
If you know the color already, Use a combine hex RGBA code, for e.g. :
<solid android:color="#80FF0000" />
Sets the color to red (0xFF0000) with 0x80 opacity.
Same thing applies to few other items. e.g. stroke
<stroke android:color="#6000FF00" android:width="20dp" />
This creates a 20dp thick green stroke of 0x60 opacity.
Futher, if you want to do it pro grammatically, i.e. modify the alpha of a specific item and not the whole drawable, use a new resource id (android:id="@+id/...") for the item and access it . I haven't happened to verify this part though.