There are a lot of buttons in the project, and many Button cutting diagrams are configured at the same time. Is Selector annoying? using the following class, you can directly add the clicking effect for the Button. No need for multiple images, no need for Selector.
 
Usage: Button. setOnTouchListener (Effect_Click.getInstance ());
 
:
 
Source code: <喎?http: www.bkjia.com kf ware vc " target="_blank" class="keylink"> VcD4KPHA + PC9wPgo8cHJlIGNsYXNzPQ = "brush: java;"> class Effect_Click implements OnTouchListener {private static Effect_Click; public static Effect_Click getInstance () {if (Effect_Click = null) {Effect_Click = new Effect_Click ();} return Effect_Click;} private Effect_Click () {}@ Overridepublic boolean onTouch (View arg0, MotionEvent arg1) {if (arg1.getAction () = MotionEvent. ACTION_DOWN) {arg0.getBackground (). setAlpha (450);} else if (arg1.getAction () = MotionEvent. ACTION_UP) {arg0.getBackground (). setAlpha (999) ;}arg0.invalidate (); return false ;}} 
 
Usage 1: Button. setOnTouchListener (Effect_Click.getInstance ());
Usage 2: You can perform secondary encapsulation. For example, you can implement your own MyButton and directly reference it in XML. in this way, as long as the background image is set for all the buttons in the project, it will naturally bring the click effect and no longer need to cut the image. 
Usage 3: introduce others and add other effects to Drawable, such as adding borders and vibration animations. add multiple effects to buttons in batches and concisely with pure code.