如果侧边打开状况下,先关闭侧边,然后在执行退出程序代码块 基于slidingmenu侧边的情况,没有侧边则去掉判断即可
@Override
public boolean onKeyDown(int keyCode, KeyEvent event) {
// TODO Auto-generated method stub
if (keyCode == KeyEvent.KEYCODE_BACK) {
long secondtime = System.currentTimeMillis();
if (secondtime - firstime > 3000) {
if (sm.isMenuShowing()||sm.isSecondaryMenuShowing()) {
return false;
}else {
Toast.makeText(MainNew.this, "再按一次返回键退出", Toast.LENGTH_SHORT).show();
firstime = System.currentTimeMillis();
return true;
}
} else {
if (sm.isMenuShowing()||sm.isSecondaryMenuShowing()) {
toggle();
}else {
finish();
System.exit(0);
}
}
// }
}
return super.onKeyDown(keyCode, event);
}
安卓点击返回按键退出应用程序
最新推荐文章于 2024-04-15 02:36:11 发布