标签:android blog io java strong sp div c on
第一步,定义一个变量,用于记录上一次按返回争键时间
private long lastBackKeyTime;
第二步,重写Activity中onKeyDown方法
@Override public boolean onKeyDown(int keyCode, KeyEvent event) { switch (keyCode) { case KeyEvent.KEYCODE_BACK: long delay = Math.abs(System.currentTimeMillis() - lastBackKeyTime); if (delay > 3000) { // 双击退出程序 Toast toast = Toast.makeText(getApplicationContext(), "再按一次 退出系统", Toast.LENGTH_SHORT); toast.setGravity(Gravity.CENTER, 0, 0); toast.show(); lastBackKeyTime = System.currentTimeMillis(); return true; } break; default: break; } return super.onKeyDown(keyCode, event); }
标签:android blog io java strong sp div c on
原文地址:http://www.cnblogs.com/mowuyan/p/4001646.html