Easy like itself . I wanna make an alpha button , which would have a selected drawable this way:
NOTE: This answer is obsolete. See the answer by kikettas for how to solve OP's problem using the compatibility library. (I would delete this answer, but SO won't let me because OP marked it as the solution.)
Original 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.
I achieved the same using a drawable
<?xml version="1.0" encoding="UTF-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android" >
<solid android:color="#5000ddff" />
</shape>
Over here used the alpha 50, which sets the opacity level. Hope that helps
I have been looking for the same thing. Even though this is posted over four years ago, this is the top post when googling the issue, so I'll reply here.
This is my solution
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:state_pressed="false">
<bitmap android:alpha="@integer/not_pressed_alpha" android:src="@drawable/item"/>
</item>
<item android:state_pressed="true" android:drawable="@drawable/item" />
</selector>