Method One
1. selector.xml files placed under drawable
Copy Code code as follows:
<android= "Http://schemas.android.com/apk/res/Android" >
android:drawable= "@drawable/temp2"/>
2. layout file Main.xml
Copy Code code as follows:
android:orientation= "Vertical"
Android:layout_width= "Fill_parent"
android:layout_height= "Fill_parent"
>
<android:layout_width= "Fill_parent"
android:layout_height= "Wrap_content"
android:text= "@string/hello"
/>
<android:drawabletop= "@drawable/shouru"
Android:layout_width= "Wrap_content"
android:layout_height= "Wrap_content"
android:text= "@string/button"
android:background= "@drawable/selector"/>
Method Two
1. layout file Main.xml
[Code]
android:orientation= "Vertical"
Android:layout_width= "Fill_parent"
android:layout_height= "Fill_parent"
>
Android:layout_width= "Fill_parent"
android:layout_height= "Wrap_content"
android:text= "@string/hello"
/>
<android:id= "@+id/button"
android:drawabletop= "@drawable/shouru"
Android:layout_width= "Wrap_content"
android:layout_height= "Wrap_content"
android:text= "@string/button"
android:background= "@drawable/temp4"/>
2. The main Java code to achieve the click Effect:
Copy Code code as follows:
Button button = (button) This.findviewbyid (R.id.button);
Button.setontouchlistener (New Button.ontouchlistener () {
@Override
public boolean Ontouch (View V, motionevent event) {
if (event.getaction () = = Motionevent.action_down) {
V.setbackgroundresource (R.DRAWABLE.TEMP1);
LOG.I ("testandroid button", "Motionevent.action_down");
}
else if (event.getaction () = = motionevent.action_up) {
V.setbackgroundresource (R.DRAWABLE.TEMP2);
LOG.I ("testandroid button", "motionevent.action_up");
}
return false;
}
});