Kotlin /anko

Pleasant Android application development

★ 15,754⑂ 1,262👁 13⑃ 149● 616▤ 26
KotlinApache-2.0Created 2014-09-18
More from this author
Download: Anko 0.10.8Anko-0.10.8 ↓0.10.82018-11-09
+0
Daily
15,754
stars
1,262
forks
13
watchers
149
prs
616
issues
26
releases

README

![Download ](https://bintray.com/jetbrains/anko/anko/_latestVersion)




:warning: Anko is deprecated. Please see this page for more information.

  

Anko is a Kotlin library which makes Android application development faster and easier. It makes your code clean and easy to read, and lets you forget about rough edges of the Android SDK for Java.

Anko consists of several parts:

 Anko Commons: a lightweight library full of helpers for intents, dialogs, logging and so on;
 Anko Layouts: a fast and type-safe way to write dynamic Android layouts;
 Anko SQLite: a query DSL and parser collection for Android SQLite;
 Anko Coroutines: utilities based on the kotlinx.coroutines library.

 Anko Commons

Anko Commons is a "toolbox" for Kotlin Android developer. The library contains a lot of helpers for Android SDK, including, but not limited to:

 Intents (wiki);
 Dialogs and toasts (wiki);
 Logging (wiki);
 Resources and dimensions (wiki).

 Anko Layouts (wiki)

Anko Layouts is a DSL for writing dynamic Android layouts. Here is a simple UI written with Anko DSL:

kotlin
verticalLayout {
    val name = editText()
    button("Say Hello") {
        onClick { toast("Hello, ${name.text}!") }
    }
}


The code above creates a button inside a LinearLayout and attaches an OnClickListener to that button. Moreover, onClick accepts a suspend lambda, so you can write your asynchronous code right inside the listener!

Note that this is the complete layout code. No XML is required!

Anko has a DSL for ConstraintLayout since v0.10.4



There is also a plugin for Android Studio that supports previewing Anko DSL layouts.

 Anko SQLite (wiki)

Have you ever been tired of parsing SQLite query results using Android cursors? Anko SQLite provides lots of helpers to simplify working with SQLite databases.

For example, here is how you can fetch the list of users with a particular name:

kotlin
fun getUsers(db: ManagedSQLiteOpenHelper): List = db.use {
    db.select("Users")
            .whereSimple("family_name = ?", "John")
            .doExec()
            .parseList(UserParser)
}


 Anko Coroutines (wiki)

Anko Coroutines is based on the kotlinx.coroutines library and provides:

 bg() function that executes your code in a common pool.
 asReference() function which creates a weak reference wrapper. By default, a coroutine holds references to captured objects until it is finished or canceled. If your asynchronous framework does not support cancellation, the values you use inside the asynchronous block can be leaked. asReference() protects you from this.

 Using Anko

 Gradle-based project

Anko has a meta-dependency which plugs in all available features (including Commons, Layouts, SQLite) into your project at once:

gradle
dependencies {
    implementation "org.jetbrains.anko:anko:$anko_version"
}

Make sure that you have the $anko_version settled in your gradle file at the project level:


ext.anko_version='0.10.8'


If you only need some of the features, you can reference 

Top issues

Latest release

Anko 0.10.8 v0.10.8 2018-11-09
What's new

Kotlin 1.3.0 and kotlinx.coroutines 1.0.0

Snapshot: 2026-11-16T09:23:14Z · Data license Apache-2.0 · JSON