How do you make a Jetpack Compose screen accessible?
AndroidMid-level
In shortGive meaningful icons and images content descriptions and decorative ones null, merge related content into single TalkBack stops, give custom controls roles and states with toggleable or selectable, mark headings, expose secondary actions as custom actions, keep 48 dp touch targets, let layouts grow with 200% fonts, check contrast, and test it.
Model answer
Semantics: Compose builds a semantics tree that TalkBack, Switch Access and tests use.
contentDescriptiondescribes meaningful non-text content (“Add to favorites”); decorative images usenull.- Merge related content:
clickableandsemantics(mergeDescendants = true)make a card one stop that reads title and details together. - Roles and states: use
IconToggleButton,Checkbox,Switch, orModifier.toggleable/selectablewith aRole, so TalkBack announces “switch, on”. Custom states usestateDescription. - Structure:
heading()on section titles,traversalIndex/isTraversalGroupwhen reading order differs from layout. - Custom actions for secondary actions and gestures like swipe-to-delete.
- Touch targets of at least 48 dp (Material components handle it).
Visual: text in sp, no fixed heights around text (heightIn(min = …)), layouts that switch to vertical at large font scales (up to 200%, nonlinear since Android 14), contrast of at least 4.5:1 for body text, and never color alone for meaning (errors with isError, supporting text and error semantics).
Testing: Compose UI tests that find nodes by content description and assert roles and states, accessibility checks in Espresso and Compose tests, @PreviewFontScale and screenshot tests, plus manual TalkBack and Accessibility Scanner passes.
What they're looking for
Semantics basics, merging, roles and states, headings and traversal, custom actions, touch targets, font scaling and contrast, and automated plus manual testing.
Common mistakes
- contentDescription on every image, including decorative ones.
- Custom controls built with clickable only.
- Fixed heights that clip large text.
More android questions
- How do you make sure background work in a mobile app stops when the user leaves the screen?Mid-level
- What's the difference between a configuration change and process death on Android, and what survives each?Mid-level
- How would you modularize a large Android app, and how do you keep builds fast?Senior
- How do you store an auth token securely on Android?Mid-level