Can we set the alpha of drawable for its disable state through XML? For example by using android:state_disable.
Asked
Active
Viewed 6,476 times
4
-
question is not clear. please mention your correct requirement, then we may help you. We can disable a view (button, image button, etc.), it contains drawables. why to set alpha to drawable to disable it ? – Yugandhar Babu Dec 22 '11 at 07:40
4 Answers
3
This is my solution, hope someone finds this useful. Yes, this is and old post, but posts like this need a answer that works today since they show up when you search.
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:state_enabled="false">
<bitmap android:alpha="@integer/disabled_alpha" android:src="@drawable/item"/>
<item/>
<item android:state_enabled="true" android:drawable="@drawable/item" />
</selector>

Fredrik Metcalf
- 307
- 2
- 10
1
actually we cant set alpha for drawable instead you should use this setAlpha(int alpha) Specify an alpha value for the drawable.

Crazy Coder
- 508
- 1
- 4
- 12
-1
Drawable card_water_wave = getResources().getDrawable(R.drawable.textview_back);
card_water_wave.setAlpha(150);

Anuj Sharma
- 498
- 3
- 20
-1
See my answer to a similar question: https://stackoverflow.com/a/29078730/562365
Basically you can use the alpha of a BitmapDrawable and then use that drawable in your selector.