Creating Android dialogs with Anko
One of the really great features of Anko library is that it can help you create alert dialog quite easily and with much less code.
In this recipe, we will see how to create alert dialogs in Anko.
Getting ready
I'll be using Android Studio to write code. You also need to include the Anko library by adding the following lines to your build.gradle
file:
compile "org.jetbrains.anko:anko:$anko_version"
You can find the source code in the 2-creating-dialogs-using-anko
branch of the https://gitlab.com/aanandshekharroy/Anko-examples/ repository.
How to do it…
Let's follow the mentioned steps to create a dialog in Kotlin:
- In the first example, we will try to create a simple alert box. To create it, you just need to follow this syntax:
alert("A simple alert","Alert") { }.show()
- If you try to run it, you will see something like this:
- There are certain situations where you want the user to perform some actions, and so Anko provides you the methods for it. Check out...