连续按两次提示退出功能
该类要继承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);
}
每天积累一点,离成功就近一点