I found this Q&A Is it possible to change the left drawable of a Button in Selector xml? and it doesn't work for me. I tried this:
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:drawable="@drawable/blue_rounded_button" android:drawableLeft="@drawable/aj_share_button_drawableleft" android:state_pressed="true"/>
<item android:drawable="@drawable/blue_rounded_button_frame" android:drawableLeft="@drawable/aj_share_button_drawableleft" />
</selector>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:drawable="@drawable/aj_share_button_white_icon" android:state_pressed="true"/>
<item android:drawable="@drawable/aj_share_button_blue_icon" />
</selector>
Set selector like this:
<Button android:id="@+id/button1"
android:background="@drawable/aj_share_button_state"
android:drawableLeft="@drawable/aj_share_button_drawableleft" />
Can somebody tell me how to make this works?
I would suggest: Your button xml:
<Button android:id="@+id/button1"
android:background="@drawable/selector_aj_share_button_state"
android:drawableLeft="@drawable/selector_aj_share_button_drawableleft"
/>
selector_aj_share_button_drawableleft.xml (in your drawable folder)
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:state_focused="true"
android:state_pressed="false"
android:drawable="@drawable/aj_share_button_white_icon"/>
<item android:state_focused="true"
android:state_pressed="true"
android:drawable="@drawable/aj_share_button_white_icon" />
<item android:state_focused="false"
android:state_pressed="true"
android:drawable="@drawable/aj_share_button_white_icon" />
<item android:drawable="@drawable/aj_share_button_blue_icon"/>
</selector>
It works with left drawable now. Try to do the same thing with selector_aj_share_button_state. Hope it helps!
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