The function of code implementation is to make a button in the implementation of the press to display a light color map, when lifted up the display of the yellow pattern.
Then the pattern itself sets the shape. Of course, there can be a lack of a corner or something.
Binds the Ontouchlistener listener to the button.
Public classAppmainextendsactivity{PrivateButton Mbutton; /**Called when the activity is first created.*/ Public voidonCreate (Bundle savedinstancestate) {Super. OnCreate (savedinstancestate); Setcontentview (R.layout.main); Buttonlistener b=NewButtonlistener (); Mbutton=(Button) Findviewbyid (R.id.button1); Mbutton.setonclicklistener (b); Mbutton.setontouchlistener (b); Mbutton.setbackgroundresource (R.drawable.green); } classButtonlistenerImplementsOnclicklistener, ontouchlistener{ Public voidOnClick (View v) {if(V.getid () = =R.id.button1) {LOG.D ("Test", "cansal button---> click"); } } Public BooleanOnTouch (View V, motionevent event) {if(V.getid () = =R.id.button1) { if(event.getaction () = =motionevent.action_up) {LOG.D ("Test", "cansal button---> Cancel"); Mbutton.setbackgroundresource (R.drawable.green); } if(event.getaction () = =Motionevent.action_down) {LOG.D ("Test", "cansal button---> Down"); Mbutton.setbackgroundresource (R.drawable.yellow); } } return false; } } }
Press and raise event listener for Android Button