问题
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