在Activity中 重写一下 onKeyDown事件:
@Override
public boolean onKeyDown(int keyCode,KeyEventevent) {
//是否触发按键为back键
if (keyCode== KeyEvent.KEYCODE_BACK){
//弹出退出确认框
this.setConfrimDialogListener(new DialogInterface.OnClickListener(){
//确定按钮单击事件
@Override
public void onClick(DialogInterface dialog, intwhich) {
removeDialog(BaseView.DIALOG_YES_NO_MESSAGE);
//back键默认执行方法
//BaseView.this.finish();
//结束当前的进程(我们的程序)===>真正意义上的退出
android.os.Process.killProcess(android.os.Process.myPid());
}
});
this.setConfrimDialogText(R.string.alert_dialog_exit_confirm);
this.showDialog(BaseView.DIALOG_YES_NO_MESSAGE);
return true;
} else//如果不是back键正常响应
return super.onKeyDown(intkeyCode,event);
}
android 硬件上的back键处理
最新推荐文章于 2023-11-19 23:50:38 发布