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.