Hello, I wanna style some widgets like button. Add...
# doodle
c
Hello, I wanna style some widgets like button. Add some rounded corners and elevation. I figured out from the documentation that i need a behavior but the documentation is not very clear. 1. Is there ready to use behaviour that i can extend from? 2. Can I customize colors like primary secondary using Theme?
n
There are ready to use behaviors defined in the themes library. Take a look at BasicTheme and the modules it provides. You can also see how to use themes in the Contacts tutorial. This shows how to set the selected theme. And this shows how you register behaviors via modules. Registering a behavior module (like those found here), or defining you own (needs better docs) will let you set a Theme to auto install the behavior to any View it targets. This shows how bathe built-in
basicButtonBehavior()
module registers itself as a member of the BasicTheme. This lets it get included whenever that theme is injected. But you will also pick up any behavior registered using bindBehavior if you inject the generic Theme interface. This lets you mix and match behaviors.
Copy code
application (modules = listOf(
    basicLabelBehavior      (),          nativeTextFieldBehavior(spellCheck = false),
    nativeHyperLinkBehavior(),
    nativeScrollPanelBehavior()) {
    YourApp(
        …
        theme = instance(), // use generic Theme that selects all behaviors registered above
        themeManager = instance()
        …
    )
}
Copy code
class YourApp(
    …
    theme: Theme,
    themeManager: ThemeManager,
    …
): Application {
    init {
        themeManager.selected = theme
    }

    …
}