Giter Club home page Giter Club logo

anko's Introduction

obsolete JetBrains project Download GitHub license

Anko logo

โš ๏ธ 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:

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

Hello world

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:

fun getUsers(db: ManagedSQLiteOpenHelper): List<User> = 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:

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 any of Anko's parts:

dependencies {
    // Anko Commons
    implementation "org.jetbrains.anko:anko-commons:$anko_version"

    // Anko Layouts
    implementation "org.jetbrains.anko:anko-sdk25:$anko_version" // sdk15, sdk19, sdk21, sdk23 are also available
    implementation "org.jetbrains.anko:anko-appcompat-v7:$anko_version"

    // Coroutine listeners for Anko Layouts
    implementation "org.jetbrains.anko:anko-sdk25-coroutines:$anko_version"
    implementation "org.jetbrains.anko:anko-appcompat-v7-coroutines:$anko_version"

    // Anko SQLite
    implementation "org.jetbrains.anko:anko-sqlite:$anko_version"
}

There are also a number of artifacts for the Android support libraries:

dependencies {
    // Appcompat-v7 (only Anko Commons)
    implementation "org.jetbrains.anko:anko-appcompat-v7-commons:$anko_version"

    // Appcompat-v7 (Anko Layouts)
    implementation "org.jetbrains.anko:anko-appcompat-v7:$anko_version"
    implementation "org.jetbrains.anko:anko-coroutines:$anko_version"

    // CardView-v7
    implementation "org.jetbrains.anko:anko-cardview-v7:$anko_version"

    // Design
    implementation "org.jetbrains.anko:anko-design:$anko_version"
    implementation "org.jetbrains.anko:anko-design-coroutines:$anko_version"

    // GridLayout-v7
    implementation "org.jetbrains.anko:anko-gridlayout-v7:$anko_version"

    // Percent
    implementation "org.jetbrains.anko:anko-percent:$anko_version"

    // RecyclerView-v7
    implementation "org.jetbrains.anko:anko-recyclerview-v7:$anko_version"
    implementation "org.jetbrains.anko:anko-recyclerview-v7-coroutines:$anko_version"

    // Support-v4 (only Anko Commons)
    implementation "org.jetbrains.anko:anko-support-v4-commons:$anko_version"

    // Support-v4 (Anko Layouts)
    implementation "org.jetbrains.anko:anko-support-v4:$anko_version"

    // ConstraintLayout
    implementation "org.jetbrains.anko:anko-constraint-layout:$anko_version"
}

There is an example project showing how to include Anko library into your Android Gradle project.

IntelliJ IDEA project

If your project is not based on Gradle, just attach the required JARs from the jcenter repository as the library dependencies and that's it.

Contributing

The best way to submit a patch is to send us a pull request. Before submitting the pull request, make sure all existing tests are passing, and add the new test if it is required.

If you want to add new functionality, please file a new proposal issue first to make sure that it is not in progress already. If you have any questions, feel free to create a question issue.

Instructions for building Anko are available in the Wiki.

anko's People

Contributors

4u7 avatar abelkov avatar abreslav avatar akshaychordiya avatar calintat avatar colriot avatar cypressious avatar deva666 avatar dragas avatar eddieringle avatar fboldog avatar hendraanggrian avatar hhariri avatar kengorab avatar kizitonwose avatar kuhnroyal avatar lucky-dev avatar meoyawn avatar miha-x64 avatar mrp14 avatar natebass avatar paulblessing avatar pawegio avatar phajduk avatar remcoder avatar ribesg avatar supercilex avatar timfreiheit avatar yanex avatar yole avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

anko's Issues

DSL: Unable to refer to views outside of the current scope

Anko team,

Thanks for the great library. :)

I'm having trouble referring to views outside the current scope.

My use case is to call an EditText from a button that lives in a different layout/ViewGroup.

Please look at the below examples to see what I am trying to accomplish. It's possible that there's a way that I'm not seeing.

Example A - Button and EditText as siblings

Works! :)

override fun onCreate(savedInstanceState: Bundle?) {
    super.onCreate(savedInstanceState)
    verticalLayout {
        val name = editText() {
            id = nameId
        }
        button("Register") {
            onClick {
                toast("Hello, ${name.text}!")
            }
        }
    }
}

Example B - Button and EditText in separate ViewGroups

Won't compile - name is used outside scope

override fun onCreate(savedInstanceState: Bundle?) {
    super.onCreate(savedInstanceState)
    relativeLayout {
        verticalLayout {
            val name = editText() {
                id = nameId
            }
        }
        button("Register") {
            onClick {
                toast("Hello, ${name.text}!")
            }
        }
    }
}

Example C - Passing instantiated EditText into DSL

Runs, but name doesn't create an actual instance of editText inside relativeLayout. So there's no editText in the UI.

override fun onCreate(savedInstanceState: Bundle?) {
    super.onCreate(savedInstanceState)

    val name = editText() {

    relativeLayout {
        verticalLayout {
            val name = editText() {
                id = nameId
            }
        }
        button("Register") {
            onClick {
                toast("Hello, ${name.text}!")
            }
        }
    }

}

Example D - findViewById

Crash at runtime - findViewById returns a View, not an EditText

override fun onCreate(savedInstanceState: Bundle?) {
    super.onCreate(savedInstanceState)

    val name = editText() {

    val nameId = 1
    relativeLayout {
        verticalLayout {
            val name = editText() {
                id = nameId
            }
        }
        button("Register") {
            onClick {
                // fails with: android.view.View! cannot be cast to T
                val name = find<EditText>(nameId)
                // fails with: android.view.View! cannot be cast to android.widget.EditText
                val name: EditText = findViewById(nameId) as EditText
                toast("Hello, ${name.text}!")
            }
        }
    }

}

Many thanks for your time and attention. Let me know how I can help get this resolved.

AnkoLogger error throwable param

AnkoLogger.error() needs a default throwable param so you can make the call Log.e(String, String, Throwable) to print a stacktrace.

Layout param scope issue

Trying to nest two views that don't want default layout params doesn't work correctly due to scope. In the example below you get a runtime error because verticalLayout{}.layoutParams() tries to invoke the ScrollView layoutParams instead of LineraLayout. The workaround is to do this verticalLayout{layoutParams()} but in that case margins do not work.

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
            root = verticalLayout {
                toolbar = toolbarSupport {
                    defaultToolbar()
                    title = getLabel()
                }
                scrollView = scrollView{
                    ll = verticalLayout{

                    }.layoutParams(width = matchParent)

                }.layoutParams(matchParent, matchParent)
            }

No static method async(Landroid/support/v4/app/Fragment;Lkotlin/jvm/functions/Function1;)Ljava/util/concurrent/Future; in class Lorg/jetbrains/anko/AnkoPackage; or its super classes (declaration of 'org.jetbrains.anko.AnkoPackage'

I'm using asyncResult in one of my fragments and when I execute it the following exception occurs:

java.lang.NoSuchMethodError: No static method async(Landroid/support/v4/app/Fragment;Lkotlin/jvm/functions/Function1;)Ljava/util/concurrent/Future; in class Lorg/jetbrains/anko/AnkoPackage; or its super classes (declaration of 'org.jetbrains.anko.AnkoPackage' appears in /data/app/pacakge.name/base.apk)

Also when compiling with ProGuard enabled the following warning appears:

Warning: de.busliniensuche.android.BookingSummaryServiceFragment: can't find referenced method 'java.util.concurrent.Future asyncResult(android.content.Context,kotlin.jvm.functions.Function0)' in program class org.jetbrains.anko.AnkoPackage

I'm using Anko 0.6.2-19s and Kotlin 0.12.412 with Gradle.

Performances

Can you achieve the performances of an annotation processor with Anko ?

Add CHANGELOG.md

It would be useful to add CHANGELOG.md file to enable quick sync with library changes for its users. Parsing commit log trying to filter essential changes is rather troublesome.

intentFor parameters and documentation

First of all, the documentation should be updated to reflect the renaming of the function Intent to intentFor.

The documentation states that parameters can be given to Intent, but the function intentFor does not take any parameter.

Just like the function startActivity, I believe it should take vararg params: Pair<String, Any> as parameter.

outside layoutParams

Let's said I want to make a a listview item with a fixed size. In order to do that with anko I need to put it inside another ViewGroup.

Custom listView adapter

Is it possible (and how) to create a custom adapter for a listview, with a custom layout? ArrayAdapter constructor requires an id of the layout, like here:

        listView {
            adapter = ArrayAdapter(ctx, android.R.layout.simple_list_item_1, listOf("a", "b"))
        }

Set style?

I can't seem to find a good way of setting a style for a view. For example if I wanted a large ProgressBar in XML I would write:

<ProgressBar
        style="@android:style/Widget.DeviceDefault.Light.ProgressBar.Large"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content" />

How do you do this in anko?

Kotlin M11 Support

Is there an estimate as to when a Koan release will be out that's built against M11?

Android Layout variations

I would like to know, how to use anko to handle android layout variations like layout-land or layout-sw600dp?
It would great if you can provide sample code.

[discussion] set layout pattern

The problem: To me there was no apparent way to get references to the root view of DSL scripts. So I thought of this way to sort of mimic the framework setContent api and get us a reference to our DSL root. I'm new to kotlin and anko so feedback is much appreciated.

The solution:

abstract class BaseActivity : RxAppCompatActivity(), AnkoLogger{

    var layout : View by Delegates.notNull()

    fun setLayout(inflate : () -> View ){
        layout = with(this){
            inflate()
        }
    }
}

usage

class Main : BaseActivity() {

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setLayout{
            frameLayout {
                backgroundColor = Color.RED
            }
        }

    }

    override fun onResume(){
        super.onResume()
        debug(layout)
    }
}

SingleColumnParser/ScalarColumnParser: wrong precondition

Both parseRow() methods throw an exception if the column count is != 0 instead of when it is != 1:

override fun parseRow(columns: Array): T {
    if (columns.size() != 0)
        throw SQLiteException("Invalid row: row for SingleColumnParser must contain exactly one column")
    [suppress("UNCHECKED_CAST")]
    return columns[0] as T
}

Context.uiThread is private

Activity has runOnUIThread {} but

  • A Fragment must call getActivity().runOnUiThread {}
  • A Service must call Handler(Looper.getMainLooper()).post {}

Anko has a Context.uiThread method but it is private and only meant to be used for Async contexts through AnkoAsyncContext.uiThread.

It would be great to give all Android system component their own uiThread {} method.

Add example of embedded fragment in activity

I searched a bit and I couldn't seem to figure out how to embed a fragment in my activity.

For example I want to do something like this.

frameLayout {
    linearLayout {
        baselineAligned = false
        orientation = LinearLayout.HORIZONTAL

        fragment {
            name = "FragmentClass"
        }.layoutParams(width = matchParent, height = matchParent)

    }.layoutParams(width = matchParent, height = matchParent)
}

How to override AnkoLogger tag

When I try to override the log tag I get an IllegalAccessError. What am I doing wrong?

abstract class BaseActivity : RxAppCompatActivity(), AnkoLogger by KoatLogger(){

}

//... off in some other file
class KoatLogger : AnkoLogger {
override val loggerTag = "koat"
}

How to use appcompat views ?

I am trying to add a appcompat toolbar using anko but can't find any example or guide. An example will help a lot.

custom views, view attrs, attrs

  1. It doesn't support custom view good enough - custom attrs.
  2. It also doesn't support all included attrs (like minHeight)
  3. How do I set background=?primaryColor?

_ScrollView does not implement MarginLayoutParams receiver

The example will repro the stacktrace at the bottom on Android 5.0.0

You may need a theme with the actionbar enabled. I am using android:Theme.Material.Light.DarkActionBar

class MainActivity() : Activity() {
    override fun onCreate(state: Bundle?) {
        super.onCreate(state)

        scrollView {
            verticalLayout {
                editText()
            }.layoutParams() {}
        }
    }
}
  java.lang.ClassCastException: android.view.ViewGroup$LayoutParams cannot be cast to android.view.ViewGroup$MarginLayoutParams
      at android.widget.ScrollView.measureChildWithMargins(ScrollView.java:1252)
      at android.widget.FrameLayout.onMeasure(FrameLayout.java:430)
      at android.widget.ScrollView.onMeasure(ScrollView.java:337)
      at android.view.View.measure(View.java:17430)
      at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:5463)
      at android.widget.FrameLayout.onMeasure(FrameLayout.java:430)

Koan and MPAndroidChart together

Hello @yanex,

I would like use koan and MPAndroidChart together because a dsl it's very good way for me. But I don't know how can I use a several code constructions. For example exists a code https://github.com/PhilJay/MPAndroidChart/blob/master/MPChartExample/src/com/xxmassdeveloper/mpchartexample/LineChartActivity1.java#L62 but I cannot use this construction in my code. Also I would like use like ... { data = data }... instead of ... { setData(data) } ... and also the same in similar cases. This is my repository https://github.com/xgrommx/KoanMPAndroidChartExample/blob/master/app/src/main/kotlin/com/gromm/koanexample/MainActivity.kt#L39

Use of getTag for listeners with multiple functions

For things like TextView.addTextChangedListener, Anko has three diferent functions: beforeTextChanged, onTextChanged and afterTextChanged.

Each of these three functions all start with:

val props = getTag() as? ViewProps
if (props != null) {
  /* do some magic */
}

...which means that those callback setters will only work if the view tag is set to a ViewProps object. This in turn means that the setter will not work in any of those cases:

  1. The programmer calls setTag(Object) inside the init block before calling any of those three functions.
  2. The programmer calls any of these three function on a view that was created either manually or through an inflated XML.

Moreover, these functions will fail silently, meaning that it will not work and the programmer will have very little way of understanding why.

Here is a utility that I have created that essentially does the same, but without those problems (in fact, I was using these kind of utils before Anko):

class TextWatcherFunctions : TextWatcher {
    private var _beforeTextChanged: ((CharSequence, Int, Int, Int) -> Unit)? = null
    private var _onTextChanged: ((CharSequence, Int, Int, Int) -> Unit)? = null
    private var _afterTextChanged: ((Editable) -> Unit)? = null

    override fun beforeTextChanged(s: CharSequence, start: Int, count: Int, after: Int)
            = _beforeTextChanged?.invoke(s, start, count, after)

    override fun onTextChanged(s: CharSequence, start: Int, before: Int, count: Int)
            = _onTextChanged?.invoke(s, start, before, count)

    override fun afterTextChanged(s: Editable)
            = _afterTextChanged?.invoke(s)

    public fun beforeTextChanged(function: (CharSequence, Int, Int, Int) -> Unit) {
        _beforeTextChanged = function
    }

    public fun onTextChanged(function: (CharSequence, Int, Int, Int) -> Unit) {
        _onTextChanged = function
    }

    public fun afterTextChanged(function: (Editable) -> Unit) {
        _afterTextChanged = function
    }
}

public fun EditText.addTextChangedListener(init: TextWatcherFunctions.() -> Unit): TextWatcher {
    val watcher = TextWatcherFunctions()
    watcher.init()
    addTextChangedListener(watcher)
    return watcher
}

This allows me to set only one of those functions with the syntax:

myEditText.addTextChangedListener {
    onTextChanged { /* Do something amazing :) */ }
}

In the context of Anko, instead of

editText {
    onTextChanged { /* Do something amazing :) */ }
}

it would be:

editText {
    addTextChangedListener {
        onTextChanged { /* Do something amazing :) */ }
    }
}

Of course, the wording would have to be re-thought to be closer to Anko's paradigm.

I know this adds a new block level, but I argue that this has significant advantages over the current implementation:

  1. It does not prevent the programmer from using tags
  2. It does not fail silently
  3. It is compatible both inside and outside Anko's building DSL
  4. The function addTextChangedListener returns the created listener, allowing the programmer to later call removeTextChangedListener. Although, to be complete, it would be cleaner for it to return an rxjava like Subscription object on which to call an unsubscribe.
  5. It is closer to Android, and IMHO, easier for Android Java programmers to understand.

What do you think ?

Suggestion for using 10.dip or 10.dp

fun dipToPx(dp: Int): Int {
return dp * Resources.getSystem().getDisplayMetrics().density.toInt()
}

val Int.px: Int
get(){
return this
}

val Int.dp: Int
get(){
return dipToPx(this);
}
val Int.dip: Int
get(){
return dipToPx(this)
}

Support v7 tinting

It looks like the default support v7 appcompat tinting is disabled if you use anko.
Is there any solution other than adding those?

public fun ViewManager.appCompatEditText(init: AppCompatEditText.() -> Unit = {}): AppCompatEditText =
        __dslAddView({ AppCompatEditText(it, null) }, init, this)

public fun ViewManager.appCompatCheckBox(init: AppCompatCheckBox.() -> Unit = {}): AppCompatCheckBox =
        __dslAddView({ AppCompatCheckBox(it, null) }, init, this)

public fun ViewManager.appCompatRadioButton(init: AppCompatRadioButton.() -> Unit = {}): AppCompatRadioButton =
        __dslAddView({ AppCompatRadioButton(it, null) }, init, this)

Incompatible with Kotlin M12

The latest anko release is only compatible with M11. Is there a workaround to make it wirk with M12 until the next version is released?

Seperate DSL library from Utility functions

Hi,

Im not a big fan of the ank DSL style but the extension functions are really awesome. If would be nice if you could split the two libraries and make it possible to only include the extension functions in projects.

Anko DSL preview creates Exception and prevents *any* kotlin project to Load in AS 1.2

Windows 8.1 64 / android-studio-bundle-141.1903250-windows / Kotln 0.12.200

Error when opening any Kotlin project:

"Cannot load project: com.itellij.ide.plugins.PluginManager$StartupAbortedException:
com.intellij.diagnostic.PluginException:
kotlin.properties.Delegates.lazy(Lkotlin/Function0;)LKotlin/properties/ReadOnlyProperty;(Plugin:org.jetbrains.kotlin.android.dsl)"

unsupported library format

when updating to AS 1.3 I had to bump the plugin version and also kotlin to 0.12.200 - now I only get an error for anko - saying it has an unsupported format

Problem with Intent and missing anko's startActivityForResult

I found 2 problems with the Intent function:

  1. It collides with android.content.Intent, making it difficult to use if I'm in an activity that overrides functions like onActivityResult or onNewIntent. Since Activity already has a property intent, I propose to rename the function to intentFor or newIntent.
  2. When I use it, I get an error: "Type argument is not within its bound. Expected: java.lang.class<_>. Found: com.my.MyActivity". When I ctrl+click on it, I get the signature of the function with the type parameter being reified T : java.lang.Class<_>. I guess it should only bereified T : Any.

Also, Anko provides a utility function startActivity but not startActivityForResult.

Finally, startActivity is defined for Activity and android.app.Fragment but not for android.support.v4.app.Fragment

set[Property]Size with a dimension resource

For each size, there should be an easy way to set a resource dimension.

Also, when setting a text size from a resource dimension, COMPLEX_UNIT_PX must be passed.

As an example, here's my extension method to TextView to set a textSize from a dimension resource:

public var TextView.textSizeDimen: Int
    get() = throw AnkoException("'textSizeDimen' property doesn't have a getter")
    set(res) = setTextSize(TypedValue.COMPLEX_UNIT_PX, getContext().getResources().getDimension(res))

Make DSL language extendable

I am attempting to make reusable components but there is no easy way to do it that I can see. Here is what I'm attempting. We need each generated _Class to also extend a _View trait so we can easily extend all of them as if were were writing an extension function on View.

Use case:

fun _FrameLayout.defaultToolbar() : Toolbar{
    return with(this){
        toolbarSupport{
            setTitle("hello")
            setElevationCompat(getContext().dip(4))
            backgroundColor = getContext().attribute(R.attr.colorPrimary).data
        }.layoutParams(width = matchParent, height = getContext().attrAsDimen(R.attr.actionBarSize))
    }
}
class Main : BaseActivity() {

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        frameLayout {
            val toolbar = defaultToolbar()
        }
    }
}

Now switching from frameLayout to say LinearLayout would require another extension function for _LinearLayout and so on for every ViewGroup you want to resuse the layout in. It would be great to do something like this instead.

fun _ViewGroup.defaultToolbar() : Toolbar{
    return with(this){
        toolbarSupport{
            setTitle("hello")
            setElevationCompat(getContext().dip(4))
            backgroundColor = getContext().attribute(R.attr.colorPrimary).data
        }.layoutParams(width = matchParent, height = getContext().attrAsDimen(R.attr.actionBarSize))
    }
}

Or is there a good way to do something similar now?

Missing version 0.6-19s in JCenter

As you can see here, the Anko JCenter repository contains versions 0.6-15, 0.6-15s and 0.6-19 but no 0.6-19s.
So we can't have both the SDK 19 features and the support library.

Why can't layoutParams be called inside of init functions?

frameLayout{ layoutParams(matchParent, matchParent)}
vs the recommended
frameLayout{ }.layoutParams(matchParent, matchParent)

I see doing it the first way only works partially, some attributes do not work like margins. I think the required way really hurts the readability of the layout it would be preferable to put it inline.

Horizontal progress bar

[suppress("NOTHING_TO_INLINE")]
public inline fun ViewManager.horizontalProgressBar(): android.widget.ProgressBar = horizontalProgressBar({})
public inline fun ViewManager.horizontalProgressBar(inlineOptions(InlineOption.ONLY_LOCAL_RETURN) init: android.widget.ProgressBar.() -> Unit): android.widget.ProgressBar = addView {
    ctx ->
    val view = android.widget.ProgressBar(ctx,null,android.R.attr.progressBarStyleHorizontal)
    view.init()
    view
}

Not sure if null is the right thing to put though.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.