Anko, makes Dialogs and alerts even easier, and in this article we’ll see how.
Alerts in Kotlin with Anko
Writing alerts with Anko is pretty easy. Just create an
alert
block:
alert("Testing alerts") {
...
}.show()
Within the block, you can specify some things like the title of the alert, or the buttons that you want to appear
alert("Testing alerts") {
title = "Alert"
yesButton { toast("Yess!!!") }
noButton { }
}.show()
This results in an alert like this:

You can customize the actions by using the
positiveButton
, negativeButton
and neutralButton
methods:
alert("Testing alerts") {
title = "Alert"
positiveButton("Cool") { toast("Yess!!!") }
negativeButton("Never Ever") { }
neutralButton("I'll think about it")
}.show()

And even add a custom view that, of course, you can create also with Anko:
alert {
title = "Alert"
positiveButton("Cool") { toast("Yess!!!") }
customView {
linearLayout {
textView("I'm a text")
button("I'm a button")
padding = dip(16)
}
}
}.show()

Progress Dialogs
Another interesting feature that includes Anko is to create progress dialogs, and indeterminate progress.
To give an example of the second ones, you can create a progress dialog in this simple way:
indeterminateProgressDialog("This a progress dialog").show()
The result of the previous line will be this:

Drop your comments below thanks
No comments:
Post a Comment