开发者

disable button with custom background android

开发者 https://www.devze.com 2023-02-28 23:33 出处:网络
When I have an android button and set it as disabled then the button seems as \"transparent\". I have a button with custom background for the pressed and focused state. I want to disable it from code

When I have an android button and set it as disabled then the button seems as "transparent".

I have a button with custom background for the pressed and focused state. I want to disable it from code. When I try开发者_JAVA百科 button.setEnabled(false); I disable the button but it keeps the same custom background. Any idea how to disable my custom button and changes the background as transparent too?


you should create you custom selector like this:

<selector xmlns:android="http://schemas.android.com/apk/res/android">
    <item 
    android:state_enabled="false"
        android:drawable="@drawable/btn_red" />
    <item 
        android:state_pressed="true" 
        android:state_enabled="true"
        android:drawable="@drawable/btn_orange" />
    <item 
        android:state_focused="true" 
        android:state_enabled="true"
        android:drawable="@drawable/btn_orange" />
    <item 
        android:state_enabled="true"
        android:drawable="@drawable/btn_black" />
</selector>


Maybe you could use android:state_enabled and set that to appropriate transparent drawable in your selector for this button?

0

精彩评论

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