![](/img/trans.png)
[英]How can I avoid dismissing my AlertDialog.Builder dialog when the user touch the screen?
[英]AlertDialog not dismissing when touch outside
我正在嘗試顯示一個AlertDialog
,它可以通過后退按鈕或在對話框外觸摸來關閉。 那里有很多解決方案,我知道哪個是正確的,因為我之前使用過它。 但現在我無法實現。 這是我的代碼:
AlertDialog alertDialog = new AlertDialog.Builder(activity, R.style.AppTheme_Dark_Dialog).create();
//Some setup of the dialog...
...
//This works when I press the back button
alertDialog.setCancelable(true);
//This should be the right answer of my problem
alertDialog.setCanceledOnTouchOutside(true);
alertDialog.show();
據我所知,使用真正的參數值調用此方法就足夠了:
alertDialog.setCanceledOnTouchOutside(true);
但不會工作。 有人可以啟發我嗎?
編輯:一些測試
正如Ugas所提到的,我更改了設備進行測試,並且它有效。
消除
alertDialog.setCanceledOnTouchOutside(true);
保持其他代碼不變並檢查。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.