我正在开发一个应用程序,当按下按钮时,它会打开一个带有确定和取消按钮的对话框.
I am developing an application that when the button is pressed, it opens a dialog with OK and Cancel buttons.
效果很好.
当用户按下后退按钮时,我按如下方式处理
When the user presses the back button, I am handling this as follows
public boolean onKeyDown(int keyCode, KeyEvent event)
{
if ((keyCode == KeyEvent.KEYCODE_BACK))
{
}
return super.onKeyDown(keyCode, event);
}
但是上面的方法没有被调用.我该如何处理?
But the above method is not called. How can I handle this?
dialog.setOnKeyListener(new Dialog.OnKeyListener() {
@Override
public boolean onKey(DialogInterface arg0, int keyCode,
KeyEvent event) {
// TODO Auto-generated method stub
if (keyCode == KeyEvent.KEYCODE_BACK) {
finish();
dialog.dismiss();
}
return true;
}
});
这篇关于如何在对话框中处理后退按钮?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!