How to disable the default Button color changing property on onClick

前端 未结 1 1754
迷失自我
迷失自我 2021-01-16 15:40

For the default android button, when I click on it, its color is changed to orange for a few seconds (for notifying the user the button is clicked). Anyway, I don\'t want th

相关标签:
1条回答
  • 2021-01-16 16:33

    Have a look on how button is styled by Android:

    <selector xmlns:android="http://schemas.android.com/apk/res/android"> 
        <item android:state_window_focused="false" android:state_enabled="true"
            android:drawable="@drawable/btn_default_normal" /> 
        <item android:state_window_focused="false" android:state_enabled="false"
            android:drawable="@drawable/btn_default_normal_disable" /> 
        <item android:state_pressed="true" 
            android:drawable="@drawable/btn_default_pressed" /> 
        <item android:state_focused="true" android:state_enabled="true"
            android:drawable="@drawable/btn_default_selected" /> 
        <item android:state_enabled="true"
            android:drawable="@drawable/btn_default_normal" /> 
        <item android:state_focused="true"
            android:drawable="@drawable/btn_default_normal_disable_focused" /> 
        <item
             android:drawable="@drawable/btn_default_normal_disable" /> 
    </selector>
    

    To style your button with Android's themes images resources, just create your own selector by copying the Android's one and replace all @drawable/btn_default_* by @android:drawable/btn_default_normal in items tag (and just remove items you don't want). For example :

    <selector xmlns:android="http://schemas.android.com/apk/res/android"> 
        <item android:state_enabled="true"
            android:drawable="@android:drawable/btn_default_normal" /> 
    </selector>
    

    Then, apply this drawable selector as a android:background of your button.

    Hope it helps.

    (If you want, I can also provide an example of applying this background easily to all your buttons, just ask.)

    0 讨论(0)
提交回复
热议问题