I have a left drawable assigned to a button as well as a background drawable. I want to supply a selector so that when a user presses/focuses/disables the button, its appearance changes. The image I am using for the left drawable is a red "x".
I would like this to swap out with a gray "X" while the button is pressed or disabled. Is this possible using a selector?
Here is what I tried (which works for the border/background image, but not for the left drawable (obviously).
<?xml version="1.0" encoding="utf-8" ?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item
android:state_enabled="false"
android:drawable="@drawable/GrayBorder"
android:drawableLeft="@drawable/GrayRemove"/>
<item
android:state_pressed="true"
android:state_enabled="true"
android:drawable="@drawable/GrayBorder"
android:drawableLeft="@drawable/GrayRemove" />
<item
android:state_focused="true"
android:state_enabled="true"
android:drawable="@drawable/GrayBorder"
android:drawableLeft="@drawable/GrayRemove" />
<item
android:state_enabled="true"
android:drawable="@drawable/BlackBorder"
android:drawableLeft="@drawable/Remove"/>
</selector>
Create a separate selector and try setting that as the drawableLeft
on your 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