Making buttons have different background images in different States is the main category of this article.
Create a new buttonstyle. xml file under Res/drawable, which is used to describe the style of the button
<?xml version="1.0" encoding="utf-8"?><selector xmlns:android="http://schemas.android.com/apk/res/android" > <item android:state_pressed="true" android:drawable="@drawable/btn_p"/> <item android:state_pressed="false" android:drawable="@drawable/btn_n"/></selector>
There are also many styles such
Add a button to the layout file and use buttonstyle. xml
<?xml version="1.0" encoding="utf-8"?><LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="fill_parent" android:layout_height="fill_parent" android:orientation="vertical" > <TextView android:layout_width="fill_parent" android:layout_height="wrap_content" android:text="@string/hello" /> <Button android:id="@+id/button1" android:layout_width="wrap_content" android:layout_height="wrap_content" android:background="@drawable/buttonstyle" /></LinearLayout>
This completes the button style.