August 2017
Intermediate to advanced
440 pages
10h
English
Anko is a library that provides a DSL to define Android views without any XML layouts. This is pretty similar to examples we've already seen, but Anko made it possible to fully remove XML layout files from a project. Here is an example view written in the Anko DSL:
verticalLayout {
val name = editText()
button("Say Hello") {
onClick { toast("Hello, ${name.text}!") }
}
}
And here is the result:

Source: https://github.com/Kotlin/anko
It is also possible to define much more complex layouts using the Anko DSL. These views can be placed either on a custom class that serves as a view or even directly inside the onCreate method:
override ...
Read now
Unlock full access