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 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?
Navigate to Android > Restrictions > Basic and click on Configure. Under Allow Device Functionality, you'll have the options to disable Home/Power button. Home Button-Uncheck this option to restrict users from using the Home Button. Power Off-Uncheck this option to restrict users from turning their devices off.
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?
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With