0

Im having a trouble how to disable when clicking outside sweet alert , When I click outside the sweetdialog the sweet dialog gone I already tried dialog.setCancelable(false); dialog.setCanceledOnTouchOutside(false); and setFinishOnTouchOutside(false); but it seems it conflicts, please try this out below is my current code , thanks in advance

enter image description here

MainActivity.java

public void alert_dialog(){
    new SweetAlertDialog(MainActivity.this,SweetAlertDialog.SUCCESS_TYPE)
            .setTitleText("Good jobss!")
            .setContentText("You clicked the button!")
            .show();
}
MackyRV
  • 15
  • 8

2 Answers2

1

You should just refer the SweetAlertDialog by a variable and then set it to cancelable. like this Java

SweetAlertDialog sDialog = new SweetAlertDialog(this, SweetAlertDialog.SUCCESS_TYPE)
sDialog.setCancelable(false);
sDialog.show;

Kotlin

val dialog = SweetAlertDialog(this, SweetAlertDialog.SUCCESS_TYPE)
            dialog.setCancelable(false)
            dialog.show()
Dhia Shalabi
  • 1,332
  • 1
  • 13
  • 29
0

I just realized I shoud make an variable declared final

   final SweetAlertDialog pDialog = new SweetAlertDialog(
                    MainActivity.this, SweetAlertDialog.SUCCESS_TYPE);
            pDialog.setTitleText("Good jobss");
            pDialog.setContentText("You clicked the button!")
            pDialog.show();
            pDialog.setCancelable(false);
MackyRV
  • 15
  • 8