0

I used the answer from Cengiz Can from here

How to make a "do not ask me again" dialog pop-up box? Android

to set up a "never show again" dialog popup. It works but when the user clicks outside of the popup dialog, it closes.

How can I block the user from clicking outside in order that my popup does not get closed.

The dialog just should get closed when the user clicks "cancel" or "Ok" and not by clicking outside the box anywhere in the layout.

Is there a method to avoid this?

Thank you

Blnpwr
  • 1,793
  • 4
  • 22
  • 43

3 Answers3

2

Add set builder.setCancelable(false); in your dialog builder. it will not close user click on screen apart from button.

Jarvis
  • 1,714
  • 2
  • 20
  • 35
2

Add this line builder.setCancelable(false);

Example

AlertDialog.Builder builder = new AlertDialog.Builder(this);
builder.setMessage("Test");
builder.setPositiveButton("ok", null);
builder.setCancelable(false);
builder.show();
Vishal Yadav
  • 3,642
  • 3
  • 25
  • 42
1

If you want to avoid closing the dialog with the back key :

setCancelable(false);

If you want to avoid closing the dialog touching outside :

setCanceledOnTouchOutside(false);
from56
  • 3,976
  • 2
  • 13
  • 23