Uncle also said Xamarin ~ Android ~ Listen to the Return key, click back to a webView, double-click to exit, xamarinwebview

Source: Internet
Author: User

Uncle also said Xamarin ~ Android ~ Listen to the Return key, click back to a webView, double-click to exit, xamarinwebview

This operation is easy to implement in native android, and it is not difficult in xamarin. There is an OnKeyDown method in the activity. We only need to rewrite it, then you can reload the page to be returned through webView. Of course, the operation is somewhat rigid, but it still has a good effect!

The principle of implementation is to set a time in the activity, and assign the time value after clicking and compare it with the current time. If it is within 2 seconds, it is considered as a double-click operation, of course, you can set this interval by yourself. After you think it is a double-click operation, you can execute the Finish () method to return to the main window. Of course, you can also set your own behavior by clicking the operation, in this example, a new page is opened in webView.

DateTime? LastBackKeyDownTime; public override bool OnKeyDown (Keycode keyCode, KeyEvent e) {if (keyCode = Keycode. Back & e. Action = KeyEventActions. Down) {if (! LastBackKeyDownTime. hasValue | DateTime. now-lastBackKeyDownTime. value> new TimeSpan (0, 0, 2) {Toast. makeText (this. applicationContext, "exit the program again", 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

 

 

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.