Your First Composable
Create and preview a composable function.
Your First Composable
A composable is just a Kotlin function marked with @Composable. Let's write one that greets a user by name.
@Composable
fun Greeting(name: String) {
Text(text = "Hello, $name!")
}The @Composable Annotation
The @Composable annotation tells the compiler this function can emit UI and can call other composables. Without it, you cannot call Text, Button, or other UI functions.
All lessons in this course
- What Is Jetpack Compose?
- Your First Composable
- Text, Image, and Button
- Previews and Hot Reload