How to prevent the dialog box (warning) from closing when touched from the outside or to stop using Anko

I use kotlin and anko to create a warning / dialog (code below), but when you click outside or push it, it closes.

Here is the code

alert("TITLE") {
    title("Text")
    positiveButton("Ok") { action() }
}.show()

This is how the solution will be in java (without using anko too)

dialog.setCancelable(false); // for prevent on back pressed
dialog.setCanceledOnTouchOutside(false); // for prevent on touching outside

Any ideas on how to achieve this using kotlin and anko? Thank:)

+4
source share
1 answer

AnkoThe library provides functionality to close a dialog box when clicked outside the dialog box. There is to provide this functionality. kotlin cancellable(BOOLEAN) alert

, .

alert("Testing alerts") {
                title("Alert")
                cancellable(false)  ////SET TRUE/FALSE ACCORDING TO URS REQUIREMENT
                positiveButton {
                   ///PERFORM ANY TASK HERE
                    dismiss()
                }
                negativeButton {
                    dismiss()
                }
            }.show()
+2

Source: https://habr.com/ru/post/1681516/


All Articles