Android: AlertDialog - User click somewhere else [duplicate]

怎甘沉沦 提交于 2019-12-14 01:08:51

问题


I have an Alert-dialog with 2 buttons( Yes/No ) If user click yes or no the alert dialog behave normal and get into on-click method, but if user click or touch somewhere outside of alert dialog it just disappear, and nothing will happen, Is there any way to prevent dialog from disappearing when user clicked somewhere else???


回答1:


Prevent dismiss dialog box on outside touch use this

 dialog.setCanceledOnTouchOutside(false);



回答2:


Add this line to your AlertDialog..

alertDialog.setCanceledOnTouchOutside(false);

For more read here Dialog cancel




回答3:


You must give this line.

alertDialog.setCanceledOnTouchOutside(false);

on bottom of the your AlertDialog.




回答4:


Yes Use

YourAlertDialog.setCanceledOnTouchOutside(false);



回答5:


use

alertDialog.setCanceledOnTouchOutside(false);

also you can use given below line for a practice that alert dialog can only go away by pressing the buttons

 alertDialog.setCancelable(false). 

This will make it so it can only go away by pressing the buttons.




回答6:


I usually use the combination of:

alertDialog.setCancelable(false); 
alertDialog.setCanceledOnTouchOutside(false);


来源:https://stackoverflow.com/questions/22627663/android-alertdialog-user-click-somewhere-else

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!