Possible Duplicate:
How to Change color of Button in Android when Clicked?
I want to change the color of button when it clicked... How i can do it? I don't want to do it by using drawable folder...
use a selector
, create a file xml in your drawable/
folder and name it bg_button.xml
:
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:drawable="@drawable/back_button_clicked" android:state_pressed="true"></item>
<item android:drawable="@drawable/back_button_clicked" android:state_focused="true"></item>
<item android:drawable="@drawable/back_button_normal"></item>
</selector>
and then in your xml layout , define your button like this :
<Button android:id="@+id/button"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@drawable/bg_button" />
NB : back_button_clicked
and back_button_normal
are drawables
for the background of your button
.
the drawable back_button_clicked
will be the background of your button when it will be clicked , and back_button_normal
will be the background of your button in normal case.
EDIT : here is a tutorial for more explanation . and here is another one