A lot of buttons in the project, while configuring a lot of button cut, selector is not very annoying, using the following class, you can directly to the button to increase the click effect. No more pictures, no selector.
Usage: Button.setontouchlistener (effect_click.getinstance ());
:
Source:
Class Effect_click implements Ontouchlistener {private static effect_click 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 () = = Motioneven T.action_down) {Arg0.getbackground (). Setalpha ();} 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 carry out two packages, such as implementing your own mybutton, directly in the XML reference. So that all the buttons in the project as long as set the background map, it will be natural with the click Effect, no longer need to cut the diagram.
Usage 3: The transparent processing, but also can add other special effects to drawable, such as increasing the frame, increase animation, etc., with pure code batch and concise to the button to add rich effects.