Pressed android button state

前端 未结 1 1939
耶瑟儿~
耶瑟儿~ 2020-12-06 18:43

I\'ve been following a tutorial that explains how to use background for a button with different states but it doesn\'t seem to work :S

Here is my code :

<         


        
相关标签:
1条回答
  • 2020-12-06 19:14

    Is the Button the only thing you have displayed in your Activity? If so, then it will be focused (triggering the third item in your selector) when the window loads, and you won't be able to navigate away from it. If you want to change only when pressed, delete that third line. While you're at it, delete the first line, as the button will never be pressed when the window isn't focused.

    In fact, I suggest this code:

    <?xml version="1.0" encoding="utf-8"?>
    <selector xmlns:android="http://schemas.android.com/apk/res/android">
        <item android:drawable="@drawable/boutonnpousse" android:state_pressed="true"/>
        <item android:drawable="@drawable/boutonn"/>
    </selector>
    
    0 讨论(0)
提交回复
热议问题