开发者

Setting alpha on a BitmapDrawable in XML

开发者 https://www.devze.com 2023-04-08 23:11 出处:网络
I was wondering if its possible to set transparency in XML for a Drawable. In this case its setting the disabled state of a button. Instead of using a separate image i should like to create a gr开发者

I was wondering if its possible to set transparency in XML for a Drawable. In this case its setting the disabled state of a button. Instead of using a separate image i should like to create a gr开发者_运维百科ayed-out version by changing the alpha. I know I could do that in code. But can it also be predefined in XML?


Since: API Level 11 it is possible for View. but if we are talking about ImageView there is a tint attribute ans it's since 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


I have been looking for the same thing. Even though this is posted over four years ago, this is one of 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_enabled="false">
        <bitmap android:alpha="@integer/disabled_alpha" android:src="@drawable/item"/>
    <item/>
    <item android:state_enabled="true" android:drawable="@drawable/item" />
</selector>
0

精彩评论

暂无评论...
验证码 换一张
取 消