Member-only story
Android Jetpack Compose
Jetpack Compose is Android’s modern toolkit for building native UIs. It simplifies and accelerates UI development on Android with less code, powerful tools, and intuitive Kotlin APIs. Read more about Jetpack Compose Basics. Google’s Android Compose code example apps. Documentation. [Github code]
Core Concepts
1. Composable Functions
Composable functions are the building blocks of Compose. They are Kotlin functions annotated with @Composable
that define a piece of your UI:
@Composable
fun Greeting(name: String) {
Text("Hello $name!")
}
Composable functions:
- Can only be called from other
@Composable
functions - Don’t return anything (return type is always
Unit
) - Are stateless by default but can manage state
- Can be reused and composed into larger UI elements
Note:
Starting with Android Studio Narwhal you can easy view your composable functions by adding the annotation @Preview
@Preview
@Composable
fun SimpleComposablePreview() {
Button(onClick = { /*TODO*/ }) {
Text("Button")
}
}
If you need to display the status and action bars inside a preview, add the…