为什么 setCanceledOnTouchOutside(false) 在警报生成器中不起作用?

时间:2023-04-24
本文介绍了为什么 setCanceledOnTouchOutside(false) 在警报生成器中不起作用?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

问题描述

我的活动中有一个警报对话框,不希望用户通过单击对话框外部来关闭它.根据我的研究(like this),我发现了 setCanceledOnTouchOutside(false); 方法.但是,我无法在我的应用程序中使用它,并且可以在使用此方法时关闭对话框.

I have an alert dialog in my activity and don't want user can dismiss it by clicking outside of the dialog. Based on my research (like this) I found setCanceledOnTouchOutside(false); method. However, I couldn't use it in my application and it is possible to dismiss dialog while I have this method.

这是我的代码:

private AlertDialog alertDialog;
alertDialog = new AlertDialog.Builder(this).create();
alertDialog.setCanceledOnTouchOutside(false);
alertDialog.setTitle("");
alertDialog.setButton(AlertDialog.BUTTON_NEUTRAL, "OK", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int which) {
        switch (intAlertAction) {
            case 1:
            case 2:
            case 3:
            default:
        }
}
});

任何建议将不胜感激.

推荐答案

这是一个有趣的问题,我想我知道你的答案.

This is an interesting question and I think I know your answer.

我一直在不同平台上测试应用程序,我注意到它们之间存在细微差别.在 android 4.0 以上,当您触摸 Toast 消息时,它就会消失.我想对话框(和 AlertDialogs)也是如此.触摸时它只是消失"(但它不会消失!-只是看不到).

I have been testing an application on different platforms and I noticed a small difference between them. Above android 4.0 when you touch a Toast message, it simply disappears. I guess it is the same with dialogs (and AlertDialogs). It simply "disappears" when touching (but it is not dismissed! - just cannot be seen).

希望对您有所帮助!

这篇关于为什么 setCanceledOnTouchOutside(false) 在警报生成器中不起作用?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

上一篇:为每个对话框更改对话框主题 下一篇:如何更改 ListPreference 对话框的外观

相关文章