Setting Alpha to BitmapDrawable in XML

I was wondering if it is possible to set transparency in XML for Drawable. In this case, it disables the state of the button. Instead of using a separate image, I would like to create a gray version by changing the alpha. I know I can do this in code. But can it also be predefined in XML?

+4
source share
2 answers

C: API Level 11 can be viewed. but if we are talking about ImageView, there is a tint attribute and it is from API level 1.

http://developer.android.com/reference/android/widget/ImageView.html#attr_android:tint

http://developer.android.com/reference/android/view/View.html#attr_android:alpha

+3
source

I was looking for the same thing. Although it was published more than four years ago, this is one of the best posts when you post this issue, so I will answer here.

This is my decision

<?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> 
+1
source

All Articles