In the XML file (there are 2 of them) I wrote the code for my buttons (pressed or not pressed). I start the emulator, but when I click on the button, its picture does not change.
What am I doing wrong?
Cleaned the project, restarted Android Studio.

enter image description here

And yet, in the settings (properties) of the button shows that everything is fine. That is, if the button is not pressed, the picture is one, if it is pressed, then another.

  • 3
    No need for a screen. Lay out the code with the text - YurySPb

2 answers 2

btn_click.xml

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

And do not forget about the button itself:

 ... android:background="@drawable/btn_click" ... 

    In both cases, you have state_pressed = "TRUE";

    Try to do this ...

     <?xml version="1.0" encoding="utf-8"?> <selector xmlns:android="http://schemas.android.com/apk/res/android"> <item android:state_pressed="true" android:drawable="@drawable/clickedbutton" /> <!-- pressed --> <item android:state_hovered="true" android:drawable="@drawable/defaultbutton" /> <!-- hovered --> <item android:drawable="@drawable/defaultbutton" /> <!-- default --> </selector> 
    • And why hovered and default? There are the same pictures - Artem Zaichikov