@Override
public boolean dispatchKeyEvent(KeyEvent event) {
// TODO Auto-generated method stub
if(event.getKeyCode() == KeyEvent.KEYCODE_BACK){
if (event.getAction() == KeyEvent.ACTION_DOWN && event.getRepeatCount() == 0) {
if(System.currentTimeMillis() - exitTime > 2000){
Toast.makeText(this, "再按一次返回键退出", Toast.LENGTH_SHORT).show();
exitTime = System.currentTimeMillis();
return false;
}
else{
MyApplication application = (MyApplication) getApplication();
application.finishAllContext();
System.exit(0);
}
}
return true;
}
return super.dispatchKeyEvent(event);
}
android中关于tabhost的返回键处理方法 onkeydown事件无效
最新推荐文章于 2021-05-27 05:47:23 发布