問題描述
我的活動中有一個警報對話框,不希望用戶通過單擊對話框外部來關閉它.根據我的研究(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) 在警報生成器中不起作用?的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!