https://kotlinlang.org logo
#anko
Title
j

jovmit

01/26/2017, 8:57 PM
@tania yes, there’s been the styles problem with anko for a little while now, and I’m not sure if they find out a way to solve it. In general, you need to use the ContextThemeWrapper to apply the style, and you can write something like this to use it for your button:
Copy code
public inline fun ViewManager.styledButton(text: CharSequence?, styleRes: Int = 0, init: Button.() -> Unit): Button {
    return ankoView({ if (styleRes == 0) Button(it) else Button(ContextThemeWrapper(it, styleRes), null, 0) }) {
        init()
        setText(text)
    }
}

public fun ViewManager.styledButton(text: CharSequence?, styleRes: Int = 0): Button = styledButton(text, styleRes) {}