Uncle also said Xamarin~android article ~ Listen back key, click Return a WebView, double-click Exit

Source: Internet
Author: User

Original: Uncle also said Xamarin~android article ~ Listen back key, click Return a WebView, double-click Exit

This operation in the native Android is very easy to implement, in Xamarin is not difficult, in the activity there are methods onkeydown, we just need to rewrite it, and then through the WebView reload to the page to return, of course, the operation is somewhat rigid, But it still has a good effect!

The implementation of the principle is to set a time in the activity, click on the time to assign the value and compare with the current time, if within 2 seconds, it is considered a double-click operation, of course, this time interval you can set yourself, after the thought of double-click operation, the execution of the finish () method can be returned to the main window, Of course, click action you can also set your own behavior, in this case, open a new page in WebView.

Datetime?Lastbackkeydowntime;  Public Override BOOLOnKeyDown (keycode keycode, KeyEvent e) {if(KeyCode = = Keycode.back && E.action = =keyeventactions.down) {if(!lastbackkeydowntime.hasvalue | | Datetime.now-lastbackkeydowntime.value >NewTimeSpan (0,0,2) {Toast.maketext ( This. ApplicationContext,"Press once again to exit the program", Toastlength.short).                    Show (); Lastbackkeydowntime=DateTime.Now; Loadurl ("/task/currenttasklist"); }                Else{Finish (); }                return true; }            return Base.        OnKeyDown (KeyCode, E); }

For knowledge, accumulation is more important than talent ~ Storage Uncle

Uncle also said Xamarin~android article ~ Listen back key, click Return a WebView, double-click Exit

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.