Xamarin~Android篇~监听返回键,单击返回某个webView,双击退出

https://www.cnblogs.com/lori/p/5088627.html

 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, "再按一次退出程序", ToastLength.Short).Show();
                    lastBackKeyDownTime = DateTime.Now;
                    loadUrl("/Task/CurrentTaskList");
                }
                else
                {
                    Finish();
                }
                return true;
            }
            return base.OnKeyDown(keyCode, e);
        }
posted @ 2017-12-24 22:31  LuoCore  阅读(1001)  评论(0编辑  收藏  举报