What is Anko Kotlin?

Anko Kotlin:

Anko is a powerful library developed by JetBrains. Its main purpose is the generation of UI layouts by using code instead of XML. This is an interesting feature, So, I recommend you to try it, but I won’t be using it in this project. However, this is not the only feature we can get from this library. Anko includes a lot of extremely helpful functions and properties that will avoid lots of boilerplate.

Anko is a library written specifically for Android, I recommend you to understand what it is doing behind the scenes. You can navigate at any moment to Anko source code using ctrl + click (Windows or Linux) or cmd + click (Mac). Anko implementation is an excellent example to learn useful ways to get the most out of the Kotlin language.

Before going any further, let’s use Anko to simplify some code. As you will see, anytime you use something from Anko, it will include an import with the name of the property or function to the file. This is because Anko uses extension functions to add new features to the Android framework. We’ll see right below what an extension function is and how to write it.

In MainActivity:onCreate, an Anko extension function can be used to simplify how to find the RecyclerView:

val forecastList: RecyclerView = find(R.id.forecast_list)

We can’t use more from the library yet, but Anko can help us to simplify, among others, the instantiation of intents, the navigation between activities, creation of fragments, database access, alerts creation, etc.