How to disable the default Button color changing p

2019-02-20 07:44发布

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 this property. I don't want to change my button color. How can I disable this property?

1条回答
▲ chillily
2楼-- · 2019-02-20 07:54

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.)

查看更多
登录 后发表回答