Skip to content
Commitwise
Menu
Android Development

Accessibility on Android

Make Compose screens work with TalkBack and Switch Access, with content descriptions, merged semantics, roles and states, headings and custom actions, 48 dp touch targets, layouts that survive 200% font scaling, sufficient contrast, and automated checks in UI tests.

intermediate

The core idea with one simple example.Step by step, with more examples and exercises.A cheat sheet: key APIs, gotchas and trade-offs.Internals, trade-offs and production pitfalls.

A user who is blind opens the recipe app with TalkBack. The screen reader says “Unlabeled button, unlabeled button, image, button” for the top bar, reads every recipe card as five separate pieces, and announces the favorite heart as just “button”, with no hint that it’s on or off. Another user, with large text at 200%, sees recipe titles cut off in half and a “Buy” button pushed off screen.

About one in six people lives with a disability, and many more use accessibility settings like large text. Jetpack Compose makes most things accessible by default, but only if you give it the information it can’t guess: what an icon means, which elements belong together, what a custom control is and what state it’s in. This lesson covers the habits that make an app usable with TalkBack, large fonts and switches, and how to check them automatically.

New to some of these? Open what you need, or skip ahead.

Basics:What is TalkBack?

TalkBack is Android’s screen reader. It reads what’s on screen aloud and lets users move between elements by swiping, and activate them by double-tapping. It relies on information the app provides: labels, roles (“button”, “switch”), states (“on”, “selected”) and grouping. iOS has the same idea in VoiceOver; see VoiceOverVoiceOverThe screen reader built into Apple platforms, which reads each element's label, value and traits aloud.Open in glossary →.

Basics:What are semantics in Compose?

Compose builds a second tree next to the UI: the semantics treeSemantics tree (Compose)The description of a Compose UI's meaning (labels, roles, states, actions) used by accessibility services and UI tests.Open in glossary →. It describes the meaning of each element for accessibility services and UI tests: its text, content description, role, state and actions. Most components (Text, Button, Checkbox) fill it in automatically; custom ones need Modifier.semantics.

Part Not started

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) gets contentDescription = 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: clickable merges 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 toggleable with Role.Switch, so TalkBack says “Vegetarian only, switch, on”, and tapping anywhere on the row toggles it.
  • heading() lets users jump from section to section.
Spot the bugThree silent buttons

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() })
}

Practice: listen to your screen

  1. Turn on TalkBack (Settings → Accessibility → TalkBack, or ask the Google Assistant).
  2. Swipe right through the screen from the top. Write down everything that’s read: is each element clear without seeing it?
  3. Find the problems: unlabeled buttons, cards read as many pieces, controls without a state, decorative images being read.
  4. Fix them with contentDescription, clickable/semantics(mergeDescendants = true), toggleable with a role, and null descriptions for decoration.
  5. 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?

  • contentDescription for meaningful non-text content, null for decorative; no “button”/“image” in labels.
  • Merge cards (clickable, semantics(mergeDescendants = true)); interactive children stay separately focusable.
  • Roles and state via toggleable/selectable with Role.*; stateDescription; onClickLabel.
  • heading(), traversalIndex/isTraversalGroup, paneTitle, liveRegion (sparingly).
  • customActions for secondary actions and swipe gestures; 48 dp targets (minimumInteractiveComponentSize).

Check this part

  1. What contentDescription should a purely decorative image have?

  2. What is the recommended minimum touch target size?

  3. How should a custom on/off control expose itself to TalkBack?

  4. How do you make swipe-to-delete on a list item accessible?

Every meaningful icon or image needs a contentDescription; decorative ones get null. Group related elements so TalkBack reads them as one (clickable and mergeDescendants do this), give custom controls a role and state (toggleable with Role.Switch, stateDescription), mark section titles as headings, and expose secondary actions as custom actions. Touch targets should be at least 48 dp.

Part Not started

Large text, contrast and automated checks

Many people increase the font size, and Android allows up to 200%. Layouts must cope:

  • Use sp for text (Compose’s text styles do), so it follows the user’s setting.
  • Don’t fix heights of things that contain text. A 40 dp tall box with 200% text cuts the text in half. Let containers grow, and let text wrap.
  • Switch layouts when space runs out: a row of a price and a “Buy” button can become a column at large font sizes.

Color and contrast:

  • Text needs enough contrast against its background: at least 4.5:1 for normal text (3:1 for large text).
  • Don’t use color alone to show meaning: an error shown only by a red border is invisible to people who don’t see red. Add an icon or text.

Testing: run Google’s Accessibility Scanner app over your screens, try them with TalkBack and 200% font, and add automated checks to your UI tests, so problems are caught on every change.

Text scales with sp; since Android 14 scaling is nonlinear (up to 200%, with large text growing less than small text), so test at the extremes with @PreviewFontScale/@PreviewScreenSizes and on devices. Avoid fixed heights and maxLines = 1 without an expansion path; adapt layouts via LocalDensity.current.fontScale or FlowRow and BoxWithConstraints at the screen level. Contrast: WCAG AA 4.5:1 body, 3:1 large text and UI components; dynamic color and dark themes must be checked too. Don’t encode meaning only in color, motion or position. Automation: Compose UI tests assert semantics (onNodeWithContentDescription, assertHasClickAction, SemanticsMatcher.expectValue(SemanticsProperties.Role, Role.Switch)), and accessibility checks (ATF) run in Espresso (AccessibilityChecks.enable()) and in Compose tests (enableAccessibilityChecks() in recent compose-ui-test versions), flagging missing labels, small targets and low contrast. Pair automation with manual TalkBack, Switch Access and Voice Access passes on key flows; involve users with disabilities in research where possible.

@Composable
fun PriceAndBuy(price: String, onBuy: () -> Unit) {
    val largeText = LocalDensity.current.fontScale >= 1.5f
    if (largeText) {
        Column(verticalArrangement = Arrangement.spacedBy(8.dp)) {            // stack at large font sizes
            Text(price, style = MaterialTheme.typography.headlineSmall)
            Button(onClick = onBuy, modifier = Modifier.fillMaxWidth()) { Text("Buy") }
        }
    } else {
        Row(verticalAlignment = Alignment.CenterVertically) {
            Text(price, style = MaterialTheme.typography.headlineSmall, modifier = Modifier.weight(1f))
            Button(onClick = onBuy) { Text("Buy") }
        }
    }
}

@PreviewFontScale                                                        // previews at several font scales
@Composable
fun PriceAndBuyPreview() = AppTheme { PriceAndBuy("€4.99", onBuy = {}) }

class RecipeRowTest {
    @get:Rule val compose = createComposeRule()

    @Test
    fun favoriteButtonIsLabeledAndToggleable() {
        var favorite = false
        compose.setContent {
            RecipeRow(sampleRecipe, isFavorite = favorite, onOpen = {}, onToggleFavorite = { favorite = !favorite })
        }
        compose.onNodeWithContentDescription("Add to favorites")
            .assertHasClickAction()
            .assertIsOff()
            .performClick()
        assertTrue(favorite)
    }

    @Test
    fun rowIsOneNodeWithAnOpenAction() {
        compose.setContent { RecipeRow(sampleRecipe, isFavorite = false, onOpen = {}, onToggleFavorite = {}) }
        compose.onNode(hasText("Lasagna") and hasClickAction()).assertExists()   // merged: title belongs to the row
    }
}
  • fontScale >= 1.5f: at large font sizes, the price and the button stack vertically, and the button gets the full width, so nothing is pushed off screen.
  • @PreviewFontScale shows the composable at several font sizes in Android Studio at once.
  • The tests find the favorite button by its description (the same thing TalkBack reads), check that it’s clickable and off, and that tapping it works. If someone removes the label, the test fails.

Predict the output

A chip is Box(Modifier.height(32.dp).background(...)) { Text(label) }. A user sets font size to 200%. What happens to the label?

Production puzzles

Spot the bugAn error only some users can see

Tap the line with the bug.

OutlinedTextField(
    value = email,
    onValueChange = onEmailChange,
    label = { Text("Email") },
    colors = OutlinedTextFieldDefaults.colors(
        unfocusedBorderColor = if (emailInvalid) Color.Red else Color.Gray,
    ),
)

Exercisehard

Make accessibility part of delivery

The team fixes accessibility bugs after complaints, and they keep coming back. Propose a process and tooling so new screens are accessible by default and regressions are caught.

›

Think about design, components, code review, automated tests and manual checks, and who owns each.

SolutionTry it yourself first
  • Design: designs specify labels for icon buttons, heading structure, focus order for complex screens, contrast-checked colors in both themes, and large-font variants of key screens.
  • Components: the design system’s components are accessible by construction (48 dp targets, roles, states, error semantics), and lint rules or code review flag raw clickable on non-semantic elements.
  • Automated checks: accessibility checks enabled in Compose and Espresso UI tests on CI; screenshot tests at 1.0, 1.5 and 2.0 font scale for key screens; tests that locate elements by content description, so labels are covered.
  • Manual passes: a TalkBack and large-font pass on changed flows before each release, using a short checklist; periodic Switch Access and Voice Access checks.
  • Ownership and metrics: an accessibility champion per team, bugs tracked with severity, and usability sessions with people who use assistive technology.
Exercisemedium

Fix the card

A news card shows an image, a headline, a source and a “bookmark” icon (24 dp, clickable, no description). TalkBack reads it as four separate items and says “unlabeled” for the bookmark. Rewrite it.

›

Which parts should be one stop, and which should stay separate?

SolutionTry it yourself first
@Composable
fun NewsCard(article: Article, bookmarked: Boolean, onOpen: () -> Unit, onBookmark: () -> Unit) {
    Row(
        Modifier.fillMaxWidth().clickable(onClickLabel = "Read article", onClick = onOpen).padding(12.dp),
        verticalAlignment = Alignment.CenterVertically,
    ) {
        AsyncImage(article.imageUrl, contentDescription = null, modifier = Modifier.size(72.dp))   // decorative
        Column(Modifier.weight(1f).padding(horizontal = 12.dp)) {
            Text(article.headline, style = MaterialTheme.typography.titleMedium)
            Text(article.source, style = MaterialTheme.typography.bodySmall)
        }
        IconToggleButton(checked = bookmarked, onCheckedChange = { onBookmark() }) {   // 48 dp, with state
            Icon(
                if (bookmarked) Icons.Filled.Bookmark else Icons.Outlined.BookmarkBorder,
                contentDescription = if (bookmarked) "Remove bookmark" else "Bookmark article",
            )
        }
    }
}

The headline and source are read together with the card’s action; the image is skipped; the bookmark is its own labeled toggle with a proper touch target.

  • sp text; nonlinear scaling up to 200% (Android 14); no fixed heights (heightIn(min =)), allow wrapping; adapt layouts by fontScale; @PreviewFontScale.
  • Contrast AA: 4.5:1 body, 3:1 large text and components, in light, dark and dynamic color; never color alone.
  • Errors via isError, supportingText, semantics { error(...) }.
  • Automation: semantics assertions in Compose tests, ATF checks in Espresso and Compose tests, font-scale screenshot tests; manual TalkBack, Switch Access, Voice Access passes.

Check this part

  1. Why avoid fixed heights for containers with text?

  2. What minimum contrast does normal body text need?

  3. How should a text field show a validation error accessibly?

  4. How do you catch missing labels automatically?

Use sp for text and let layouts grow: avoid fixed heights, allow wrapping, and switch to vertical layouts at large font scales (up to 200% with nonlinear scaling since Android 14). Check color contrast (4.5:1 for body text) and don't rely on color alone. Test with Accessibility Scanner, TalkBack, and automated checks: Compose semantics in UI tests and accessibility checks in Espresso and Compose tests.

Key takeaways

  • Label meaningful icons and images; mark decorative ones with null.
  • Group related content into one TalkBack stop; give custom controls a role and state.
  • Touch targets of at least 48 dp; text in sp that can grow to 200%.
  • Enough contrast, never color alone, and test with TalkBack and Accessibility Scanner.
  • Treat the semantics tree as an API: merging, roles, states, headings, traversal, custom actions.
  • Design layouts for nonlinear font scaling and adapt structure, not just size.
  • Automate: semantics assertions, ATF checks, font-scale screenshots in CI.
  • Make accessibility part of design, components and release checklists.

Finished this page?Nice work, this page is complete!

Mark it as done to track your progress. It's saved in this browser, no account needed.

Its cards are now in your Bites review ⚡
Esc

Type to search the whole site.