Android Pure Code Add click Effect

Source: Internet
Author: User

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.



Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.