Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android ImageButton state not changing

I have an issue with my ImageButton not changing state. When I click, or rather touch, the button it stays as the same image. Here is the XML I am using as a selector.

<selector
xmlns:android="http://schemas.android.com/apk/res/android">
<item
 android:state_focused="true"
 android:state_pressed="false"
 android:drawable="@drawable/pushed" />
<item
 android:state_focused="true"
 android:state_pressed="true"
 android:drawable="@drawable/pushed" />
<item
 android:state_focused="false"
 android:state_pressed="true"
 android:drawable="@drawable/pushed" />
<item  
 android:drawable="@drawable/default" />
</selector>

I call this selector from my main.xml as

android:background="@drawable/imagechoice"

imagechoice.xml is the file with the selector

I don't understand why this is not working, unless I have to have some java code, but everything I've seen said this should work.

like image 611
Doug Goldberg Avatar asked Dec 25 '10 19:12

Doug Goldberg


2 Answers

When using an ImageButton, isn't it the 'src' property you should use and not background?

like image 140
David Brown Avatar answered Nov 15 '22 05:11

David Brown


Make sure that you copy the same images and the button XML into every "drawable" folders (hdpi,ldpi,mdpi). That's how I solved this problem on my app.

Good luck :)

like image 2
eLLe Avatar answered Nov 15 '22 05:11

eLLe