This repository was archived by the owner on Jul 13, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Anko Commons – Dialogs
Yan Zhulanow edited this page May 11, 2017
·
14 revisions
Dialog helpers are inside the anko-common
artifact. Add it as a dependency to your build.gradle
:
dependencies {
compile "org.jetbrains.anko:anko-common:$anko_version"
}
Simply shows the Toast message.
toast("Hi there!")
toast(R.string.message)
longToast("Wow, such a duration")
A small DSL for showing alert dialogs.
alert("Hi, I'm Roy", "Have you tried turning it off and on again?") {
yesButton { toast("Oh…") }
noButton {}
}.show()
The code above will show the default Android alert dialog. If you want to switch to the appcompat implementation, use the Appcompat
dialog factory:
alert(Appcompat, "Some text message").show()
Android
and Appcompat
dialog factories are included by default, but you can create your custom factories by implementing the AlertBuilderFactory
interface.
alert()
functions seamlessly support DSL as custom views:
alert {
customView {
editText()
}
}.show()
selectors()
show the alert dialog with the text items list.
val countries = listOf("Russia", "USA", "Japan", "Australia")
selector("Where are you from?", countries) { i ->
toast("So you're living in ${countries[i]}, right?")
}
progressDialog()
creates and shows the [progress dialog].
val dialog = progessDialog(message = "Please wait a bit…", title = "Fetching data")
Indeterminate progress dialog is also available (see indeterminateProgressDialog()
).