1

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?

skynet
  • 9,898
  • 5
  • 43
  • 52
Jomia
  • 3,414
  • 10
  • 46
  • 63

1 Answers1

8

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

OcuS
  • 5,320
  • 3
  • 36
  • 45
  • Thankzz for the help, but I did not set any background color/image for this button. I just want the property for overriding the default button color changing functionality. In ur example a lots of images we should add as background – Jomia Apr 20 '11 at 09:28
  • 1
    This is how it works. For each state there is a different image. In my example, I just force background to use the same image for each state. To accomplish what you are trying to do, you'll just need one image (which is furthermore provided by Android itself). This is the easiest way to do it, you do not have to deal with any `OnClickListener` on each button you create. But it is up to you :) – OcuS Apr 20 '11 at 09:52
  • 1
    Jomia - "If you want, I can also provide an example of applying this background easily to all your buttons, just ask." Enquiring minds want to know. – John Ashmore Aug 13 '13 at 08:57