The problem

Traditionally, Android apps are primarily written in Java, a language that many, myself included, find painfully verbose. Furthermore, the vast majority of UI is defined in XML, which is also universally recognized as extremely redundant.

Of course, there are alternatives, including hybrid frameworks and kind-of-hybrid-but-native-too frameworks and fully featured native bindings. All of these solutions work to some extent, and you may even prefer them to native development. If that is the case, then go ahead and continue using your favorite frameworks!

The solution: Kotlin

But if you’re not satisfied with the alternatives and keep reluctantly returning to native development with Java, know that there is a fully compatible alternative. Kotlin is a JVM language that is fully compatible with Java, and even comes with a tool that can convert almost all Java code directly to Kotlin. Kotlin code is far more concise and elegant, and it supports wide varieties of syntactic sugar to reduce keystrokes and save time. It even has first class support for Android development (of course, that’s why I mentioned it!), and after installing a single plugin to Android Studio, you can mix Kotlin and Java in your application.

That solves one so-called “problem”: Java.

If you still hate XML Android layouts and long for a replacement, you’re: 1. not alone, and 2. in luck!

Ditch XML and switch to Anko

Anko, a DSL for Android development with Kotlin, lets you forget about all the “rough edges” of Java and XML, and instead focus on your application. With inline event handler support, a much nicer way to access views, and full compatibility with existing XML layouts, Anko will permanently change your Android development experience for the better!

Instead of some nasty XML to do the same thing, a simple UI in Anko looks like this:

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

Yes, an inline onClick listener! Yes, no findViewById! In fact, this is so amazing that I’m going to end this post and go back to my Android app with Kotlin and Anko!

I’ll probably write another post about putting together a simple app with Kotlin and Anko soon.