Android Toast Tip Press two times back key to exit

Source: Internet
Author: User

1  Public classMainactivityextendsActivity {2 3 @Override4     protected voidonCreate (Bundle savedinstancestate) {5         Super. OnCreate (savedinstancestate);6 Setcontentview (r.layout.activity_main);7 8     }9 Ten     LongStartTime; One  A @Override -      Public voidonbackpressed () { -         if(System.currenttimemillis ()-StartTime < 2000) { the             Super. onbackpressed (); -}Else { -StartTime =System.currenttimemillis (); -  +Toast toast =NewToast ( This); -  +LinearLayout layout =NewLinearLayout ( This); A layout.setorientation (linearlayout.vertical); at Layout.setbackgroundcolor (color.yellow); -              -TextView TV1 =NewTextView ( This); -Tv1.settext ("Hint"); - tv1.setgravity (gravity.center); -              inTextView TV2 =NewTextView ( This); -Tv2.settext ("Press the Back button again to exit"); to tv2.setgravity (gravity.center); +              - Layout.addview (TV1); the Layout.addview (TV2); *  $ Toast.setview (layout);Panax NotoginsengToast.setgravity (gravity.center_vertical | Gravity.fill_horizontal, 0,-200); - toast.setduration (toast.length_short); the toast.show (); +  A         } the  +     } -  $}
mainactivity

Android Toast Tip Press two times back key to exit

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.