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

why setCanceledOnTouchOutside(false) doesn#39;t work in Alert builder?(为什么 setCanceledOnTouchOutside(false) 在警报生成器中不起作用?)
本文介绍了为什么 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) 在警报生成器中不起作用?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!

本站部分内容来源互联网,如果有图片或者内容侵犯您的权益请联系我们删除!

相关文档推荐

How to target newer versions in .gitlab-ci.yml using auto devops (java 11 instead of 8 and Android 31 instead of 29)(如何在.gitlab-ci.yml中使用自动开发工具(Java 11而不是8,Android 31而不是29)瞄准较新的版本)
Android + coreLibraryDesugaring: which Java 11 APIs can I expect to work?(Android+core LibraryDesugering:我可以期待哪些Java 11API能够工作?)
How to render something in an if statement React Native(如何在If语句中呈现某些内容Reaction Native)
How can I sync two flatList scroll position in react native(如何在本机Reaction中同步两个平面列表滚动位置)
Using Firebase Firestore in offline only mode(在仅脱机模式下使用Firebase FiRestore)
Crash on Google Play Pre-Launch Report: java.lang.NoSuchMethodError(Google Play发布前崩溃报告:java.lang.NoSuchMethodError)