为什么 setCanceledOnTouchOutside(false) 在警报生成器中不起作用? [英] why setCanceledOnTouchOutside(false) doesn't work in Alert builder?

查看:23
本文介绍了为什么 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) 在警报生成器中不起作用?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆