Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is it possible to change the left drawable of a Button in Selector xml?

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>
like image 759
theMothaShip Avatar asked Aug 26 '13 23:08

theMothaShip


1 Answers

Create a separate selector and try setting that as the drawableLeft on your Button.

like image 129
Varun Avatar answered Oct 23 '22 22:10

Varun