A.Quiroga A.Quiroga - 5 months ago 56
Android Question

Is there a way to set drawable's Alpha using XML?

Easy like itself . I wanna make an alpha button , which would have a selected drawable this way:

<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">

<!-- Play/Pause -->
<item android:state_selected="false" android:drawable="@drawable/item" />
<item android:state_selected="true" android:drawable="@drawable/item" />

</selector>


I would wanna make something like this:

<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">

<!-- Play/Pause -->
<item android:alpha="125" android:state_selected="false" android:drawable="@drawable/item" />
<item android:alpha="255" android:state_selected="true" android:drawable="@drawable/item" />

</selector>


Thanks for all .

Answer

I don't think there's a way to do that. There is an attribute android:alpha, but it applies to views, not drawables. It's only been available since API level 11.

Comments