该类要继承Activity
DateTime? lastBackKeyDownTime;
public override Boolean 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;
}
else
{
Finish();
}
return true;
}
return base.OnKeyDown(keyCode, e);
}