Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Anko Superpowers

Anko Superpowers

Enzo Lizama Paredes

July 06, 2018
Tweet

More Decks by Enzo Lizama Paredes

Other Decks in Programming

Transcript

  1. <LinearLayout xmlns:android="http://schemas.android.co m/apk/res/android" android:layout_height="match_parent" android:layout_width="match_parent"> <EditText android:id="@+id/todo_title" android:layout_width="match_parent" android:layout_heigh="wrap_content" android:hint="@string/title_hint"

    /> <Button android:layout_width="match_parent" android:layout_height="wrap_content" android:text="@string/add_todo" /> </LinearLayout> verticalLayout { var title = editText { id = R.id.todo_title hintResource = R.string.title_hint } button { textResource = R.string.add_todo onClick { view -> { // do something here } } } }
  2. INTENTS Normal: val intent = Intent(this, SomeOtherActivity::class.java) intent.putExtra("id", 5) startActivity(intent)

    Anko : startActivity<SomeOtherActivity>("id" to 5) // startActivity<SomeOtherActivity>("id" to 5, "name" to "John")
  3. Alerts : alert("Hi, I'm Roy", "Have you tried turning it

    off and on again?") { yesButton { toast("Oh…") } noButton {} }.show()
  4. Selector : val countries = listOf("Russia", "USA", "Japan", "Australia") selector("Where

    are you from?", countries, { dialogInterface, i -> toast("So you're living in ${countries[i]}, right?") })
  5. • rendered by creating view object in memory from XML

    file • create view objects • find views by id with findViewById
  6. • rendered by creating view object in memory from XML

    file • create view objects • find views by id with findViewById
  7. “Anko offers several solutions to the traditional way of building

    layouts in XML. It could improve your MVVM setup, or you could make your layouts more dynamic by adding some logic. And this all for a very small cost, considering all the extreme effort we do for clean and high performing apps.” -Simon Vergauwen https://medium.com/@vergauwen.simon