Skip to the workspace
Pebellslearn by building
Building Screens with Jetpack Compose  ›  Lesson

Text, Button and Icon

Text 13 minText shows words, Button runs an action when tapped and holds its own content, and Icon draws a symbol that needs a content description unless it is decorative.

android / Text, Button and Icon

Explore each scene at your own pace.

01 · The rule

The rule

Text, Button and Icon

Sprout's plant screen needs a title, a "Water" button with a drop icon, and a way for screen-reader users to understand every part. Three composables do almost all of it: Text, Button and Icon.

The rule

Text shows, Button does, Icon hints; every icon says what it means.

Text displays a string. Style it from the theme so it stays consistent:

Text(text = plant.name, style = MaterialTheme.typography.titleLarge)

Button takes an onClick lambda, and its label is not a parameter but a content slot: a trailing lambda where you place other composables.

Button(onClick = { count++ }) {
    Icon(Icons.Filled.WaterDrop, contentDescription = null)
    Spacer(Modifier.width(8.dp))
    Text("Water")
}

Button lays its content out in a row, so the icon and word sit side by side. Variants such as OutlinedButton and TextButton work the same way.

Icon draws a symbol, often from Icons.Filled or Icons.Outlined. Its contentDescription is what screen readers such as TalkBack announce:

  • If the icon carries meaning alone, describe it: "Water plant".
  • If nearby text already says it, pass null, so it is not read twice.

For a tappable icon without a label, wrap it in IconButton, and then the description is required.

Scene 1 of 5
Hover to wake the cannons. Drag to move, or use arrow keys when focused. Press Enter to fire a shot.