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