如何在弹出对话框打开时禁用主页和后退按钮单击功能
dialog.setOnKeyListener(new Dialog.OnKeyListener() {
@Override
public boolean onKey(DialogInterface dialogs, int keyCode,
KeyEvent event) {
if (keyCode == KeyEvent.KEYCODE_BACK) {
//what should i do
}
if (keyCode == KeyEvent.KEYCODE_HOME) {
//what should i do
}
return false;
}
});

答案 0 :(得分:0)
将取消设为
dialog.setCancelable(false);
dialog.setOnKeyListener(new Dialog.OnKeyListener() {
@Override
public boolean onKey(DialogInterface dialogs, int keyCode,
KeyEvent event) {
if (keyCode == KeyEvent.KEYCODE_HOME) {
//what should i do
return true;
}
return false;
}
});
答案 1 :(得分:0)
如果您的上述代码在您的服务中有效,则只需返回true
即可。
dialog.setOnKeyListener(new Dialog.OnKeyListener() {
@Override
public boolean onKey(DialogInterface dialogs, int keyCode,
KeyEvent event) {
if (keyCode == KeyEvent.KEYCODE_BACK) {
return true;
}
if (keyCode == KeyEvent.KEYCODE_HOME) {
return true;
}
return false;
}
});
注意: 返回true
将表明系统您将处理更多事件,并且无法进一步转发event