Adaptive Layouts, Dark Mode and Accessibility
Edge-to-Edge and Insets
Modern Android apps draw behind the status and navigation bars. You handle that with insets. Scaffold does most of the work through innerPadding.
kotlin
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
enableEdgeToEdge() // draw behind system bars
setContent { App() }
}
Column(Modifier.fillMaxSize().safeDrawingPadding()) { /* content stays clear of bars and cutouts */ }
Window Size Classes
| Class | Typical device | Layout idea |
|---|---|---|
| Compact width | Phone in portrait | One column, bottom navigation |
| Medium width | Foldable, small tablet | Navigation rail, two panes when it fits |
| Expanded width | Tablet, desktop window | List and detail side by side |
kotlin
@Composable
fun AdaptiveHome() {
val windowSizeClass = currentWindowAdaptiveInfo().windowSizeClass
if (windowSizeClass.isWidthAtLeastBreakpoint(WindowSizeClass.WIDTH_DP_EXPANDED_LOWER_BOUND)) {
Row {
ListPane(Modifier.weight(1f))
DetailPane(Modifier.weight(2f))
}
} else {
ListPane(Modifier.fillMaxSize())
}
}
Why this matters: Google expects apps to work well on tablets, foldables and resizable windows. Apps that fail there can get lower quality ratings. Test with the Resizable emulator.
Dark Theme
kotlin
val dark = isSystemInDarkTheme()
// Use MaterialTheme.colorScheme everywhere, never hard-coded white or black
Surface(color = MaterialTheme.colorScheme.background) { /* ... */ }
@Preview(uiMode = Configuration.UI_MODE_NIGHT_YES, name = "Dark")
@Preview(fontScale = 1.5f, name = "Large font")
@Composable
fun ScreenPreview() { HelloAppTheme { HomeScreen() } }
Accessibility
kotlin
IconButton(onClick = onFavorite) {
Icon(Icons.Default.Favorite, contentDescription = "Add to favorites")
}
Row(Modifier.semantics(mergeDescendants = true) { }) { // read as one item
Text("Total"); Text("$20")
}
Text("Heading", Modifier.semantics { heading() })
Box(Modifier.clearAndSetSemantics { }) // hide decorative content
| Check | How |
|---|---|
| TalkBack | Turn on in Settings > Accessibility and use your app with eyes closed |
| Font size | Settings > Display > Font size, and the preview fontScale |
| Contrast | Text must stand out from its background |
| Touch targets | At least 48 x 48 dp |
| Accessibility Scanner | Free Google app that suggests fixes |
Tip: Use
Modifier.minimumInteractiveComponentSize() for custom clickable elements, and never rely on color alone to show meaning.
Conclusion
Adaptive apps use insets, size classes and theme colors. Accessible apps have descriptions, good contrast and large enough touch targets.
Quick Summary: Use edge-to-edge insets, WindowSizeClass for layouts, theme colors for dark mode and contentDescription and semantics for TalkBack.

