Making screens make sense to TalkBack
TalkBack users hear your screen instead of seeing it. So every element must say what it is and what it does:
- Icons and images that mean something need a
contentDescription: a heart icon button is “Add to favorites”, not “heart”. Pure decoration (a background pattern, an image next to a title that already says the same) getscontentDescription = null, so TalkBack skips it. - Things that belong together should be read together. A recipe card with an image, a title, a time and a rating should be one stop for TalkBack (“Lasagna, 45 minutes, 4.5 stars”), not five.
- Custom controls must say what kind of control they are and what state they’re in: “Vegetarian only, switch, on”.
- Section titles should be marked as headings, so users can jump between sections.
- Touch targets should be at least 48 × 48 dp, even if the icon is smaller, so people with limited motor control can hit them.
The semantics tree is the contract with TalkBack, Switch Access, Voice Access and tests. contentDescription for meaningful non-text content, null for decorative; avoid redundant descriptions (“button” or “image” in labels, since roles are announced). Merging: clickable, toggleable and Modifier.semantics(mergeDescendants = true) merge children into one focusable node, so a card is one stop; nested interactive children keep their own focus. Roles and states: prefer toggleable/selectable with Role.Switch/Role.Checkbox/Role.RadioButton over clickable plus visuals; stateDescription for custom states; onClickLabel to describe the action (“Double tap to open recipe”). Structure: heading() for section titles, traversalIndex/isTraversalGroup when visual order and reading order differ, paneTitle for screens, liveRegion for status changes (sparingly). Custom actions (customActions) expose secondary actions (favorite, share, delete) on list items without extra focus stops, which is also how swipe-to-dismiss must be made accessible. Material components already give 48 dp minimum touch targets (minimumInteractiveComponentSize); custom clickables need it explicitly.
@Composable
fun RecipeRow(recipe: Recipe, isFavorite: Boolean, onOpen: () -> Unit, onToggleFavorite: () -> Unit) {
val favoriteLabel = if (isFavorite) "Remove from favorites" else "Add to favorites"
Row(
Modifier
.fillMaxWidth()
.clickable(onClickLabel = "Open recipe", onClick = onOpen) // clickable merges the children
.semantics {
customActions = listOf(CustomAccessibilityAction(favoriteLabel) { onToggleFavorite(); true })
}
.padding(16.dp),
verticalAlignment = Alignment.CenterVertically,
) {
AsyncImage(model = recipe.imageUrl, contentDescription = null, modifier = Modifier.size(56.dp)) // decorative
Column(Modifier.weight(1f).padding(horizontal = 12.dp)) {
Text(recipe.title, style = MaterialTheme.typography.titleMedium)
Text("${recipe.minutes} min · ${recipe.rating} stars")
}
IconToggleButton(checked = isFavorite, onCheckedChange = { onToggleFavorite() }) { // 48 dp target
Icon(
imageVector = if (isFavorite) Icons.Filled.Favorite else Icons.Outlined.FavoriteBorder,
contentDescription = favoriteLabel,
)
}
}
}
@Composable
fun VegetarianFilter(enabled: Boolean, onChange: (Boolean) -> Unit) {
Row(
Modifier
.fillMaxWidth()
.toggleable(value = enabled, role = Role.Switch, onValueChange = onChange) // role + state for TalkBack
.padding(16.dp),
) {
Text("Vegetarian only", Modifier.weight(1f))
Switch(checked = enabled, onCheckedChange = null) // the Row handles the toggle
}
}
@Composable
fun SectionTitle(text: String) {
Text(text, style = MaterialTheme.typography.titleLarge, modifier = Modifier.semantics { heading() })
}- The whole row is one stop:
clickablemerges the title and the time, and TalkBack says “Lasagna, 45 min · 4.5 stars, double tap to open recipe”. - The image is decorative (
contentDescription = null): the title already says what the recipe is. - The favorite button has a label that describes the action and changes with the state. It’s an
IconToggleButton, so TalkBack also says whether it’s checked, and its touch target is 48 dp. - The custom action lets TalkBack users favorite a recipe from the row itself, through the actions menu, without moving to the button.
- The filter row uses
toggleablewithRole.Switch, so TalkBack says “Vegetarian only, switch, on”, and tapping anywhere on the row toggles it. heading()lets users jump from section to section.
Tap the line with the bug.
Row {
Icon(Icons.Default.Search, contentDescription = null,
modifier = Modifier.size(24.dp).clickable { onSearch() })
Icon(Icons.Default.FilterList, contentDescription = null,
modifier = Modifier.size(24.dp).clickable { onFilter() })
Icon(Icons.Default.Settings, contentDescription = null,
modifier = Modifier.size(24.dp).clickable { onSettings() })
}Hint: What does TalkBack say for each icon, and how big is each touch target?
Each icon is clickable but has no description, so TalkBack says “Unlabeled, button” three times; a blind user can’t tell search from settings. And each touch target is only 24 dp, half the recommended 48 dp, which is hard to hit for anyone with a tremor or large fingers.
Use IconButton (48 dp target, button role) with a description of the action:
Row {
IconButton(onClick = onSearch) { Icon(Icons.Default.Search, contentDescription = "Search") }
IconButton(onClick = onFilter) { Icon(Icons.Default.FilterList, contentDescription = "Filter recipes") }
IconButton(onClick = onSettings) { Icon(Icons.Default.Settings, contentDescription = "Settings") }
}Practice: listen to your screen
- Turn on TalkBack (Settings → Accessibility → TalkBack, or ask the Google Assistant).
- Swipe right through the screen from the top. Write down everything that’s read: is each element clear without seeing it?
- Find the problems: unlabeled buttons, cards read as many pieces, controls without a state, decorative images being read.
- Fix them with
contentDescription,clickable/semantics(mergeDescendants = true),toggleablewith a role, andnulldescriptions for decoration. - Try the actions menu (swipe up then right, depending on settings) on list items with custom actions.
Predict the output
A custom 'favorite' control is a Box with Modifier.clickable { toggle() } that shows a filled or empty heart drawn with Canvas. What does TalkBack announce?
clickable gives the node a click action and makes it focusable, but Compose can't know what the Canvas drawing means or that the control has an on/off state. Use Modifier.toggleable(value = isFavorite, role = Role.Switch or Role.Checkbox, onValueChange = …) plus a contentDescription (or stateDescription for custom wording), or use IconToggleButton, which provides all of it.
contentDescriptionfor meaningful non-text content,nullfor decorative; no “button”/“image” in labels.- Merge cards (
clickable,semantics(mergeDescendants = true)); interactive children stay separately focusable. - Roles and state via
toggleable/selectablewithRole.*;stateDescription;onClickLabel. heading(),traversalIndex/isTraversalGroup,paneTitle,liveRegion(sparingly).customActionsfor secondary actions and swipe gestures; 48 dp targets (minimumInteractiveComponentSize).
Check this part
What contentDescription should a purely decorative image have?
What is the recommended minimum touch target size?
How should a custom on/off control expose itself to TalkBack?
How do you make swipe-to-delete on a list item accessible?