我需要在用户按下后退键并尝试关闭对话框时捕捉一个事件 我有这样的代码
AlertDialog alertDialog = new AlertDialog.Builder(AppNotification.this).create();
alertDialog.setTitle("Caution");
alertDialog.setMessage("Alert");
alertDialog.setButton("OK", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int which) {
finish();
} });
alertDialog.show();
}
现在我给了用户一个选项,但是假设如果他按下后退键,那么我需要执行一些其他操作。该怎么做?
最佳答案
这对你有帮助
alertDialog.setOnCancelListener(new OnCancelListener() {
public void onCancel(DialogInterface dialog) {
// Your code ...
}
});
关于android - 如何在用户通过按下 Android 中的后退键关闭警报对话框时捕获事件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9289528/