· 5 min read
Android 16 Edge-to-Edge: Fix Insets Before Targeting API 36
Android 16 removes the edge-to-edge opt-out for apps that target API 36. How to find and fix inset bugs in Views and Compose before you bump targetSdk.
Android 16 edge-to-edge is not optional any more. When an app targets API 36, the system draws it behind the status bar and the navigation bar, and the old escape hatch, windowOptOutEdgeToEdgeEnforcement, stops working. Google Play now requires API 36 for app updates, so every Android team hits this sooner or later. The change looks cosmetic. It is not: a toolbar under the clock, a button under the gesture bar or a text field under the keyboard can block a real user flow. This post is the order I use to fix insets before I bump targetSdk.
I work on the native Android app at Gatewise, a smart access control app. When the main action of a screen is a button, a button hidden behind the navigation bar is not a style issue. So I treat the target SDK bump as a small feature with its own checklist, not as a one-line change in build.gradle.
What changed in Android 16 edge-to-edge
The change came in two steps.
- Android 15 (API 35) turned on edge-to-edge by default for apps that target it. Apps could still opt out with the
windowOptOutEdgeToEdgeEnforcementtheme attribute. - Android 16 (API 36) deprecated that attribute and disabled it for apps that target API 36. If your theme still has it, it does nothing.
So if your team bought time with the opt-out last year, that time is over. The official Android 16 behavior changes page lists it next to other changes, like predictive back and the large-screen orientation rules. Edge-to-edge is the one that touches almost every screen, so I fix it first and alone.
Step 1: Find every screen that needs insets
Before writing any code, I make a list. Bumping targetSdk on a branch and clicking through the app shows the problems fast. I look for four kinds of bugs:
- Top bars that slide under the status bar or the camera cutout.
- Bottom content: buttons, bottom sheets and the last item of a list hidden behind the navigation bar.
- Text fields that the keyboard covers. With edge-to-edge,
adjustResizeno longer moves your layout for you. - Custom views with hard-coded top or bottom margins that someone added years ago to "fix" the status bar.
I check each screen twice: once with gesture navigation and once with three-button navigation. The bottom inset is very different between the two, and a screen that looks fine with one often breaks with the other. Landscape and a device with a camera cutout add two more passes for the main flows.
Step 2: Fix insets in View-based screens
For XML layouts, call enableEdgeToEdge() in the activity, then apply insets as padding on the view that needs them. Do not apply them to the root of every screen by reflex. A list should scroll behind the navigation bar and only pad its last item, not shrink.
class ListActivity : AppCompatActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
enableEdgeToEdge()
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_list)
val toolbar = findViewById<View>(R.id.toolbar)
val list = findViewById<RecyclerView>(R.id.list)
ViewCompat.setOnApplyWindowInsetsListener(toolbar) { v, insets ->
val bars = insets.getInsets(
WindowInsetsCompat.Type.systemBars() or
WindowInsetsCompat.Type.displayCutout()
)
v.updatePadding(top = bars.top, left = bars.left, right = bars.right)
insets
}
ViewCompat.setOnApplyWindowInsetsListener(list) { v, insets ->
val bars = insets.getInsets(WindowInsetsCompat.Type.systemBars())
v.updatePadding(bottom = bars.bottom)
insets
}
}
}
Set android:clipToPadding="false" on the RecyclerView. Then the list draws behind the navigation bar while it scrolls, and the last item still stops above it.
Two rules save time here:
- Return the insets from the listener unless you really mean to consume them. Consuming them hides them from child views, and the bug shows up two screens later.
- Delete old hard-coded margins like
24dpat the top. They were a guess at the status bar height, and they now add space on top of the real inset.
Step 3: Fix insets in Compose screens
Compose makes this easier, because insets are just modifiers. If you use Scaffold, it passes the system bar insets to its content as innerPadding. The common bug is to ignore that parameter.
@Composable
fun ItemsScreen(items: List<Item>, onOpen: (Item) -> Unit) {
Scaffold(
topBar = { TopAppBar(title = { Text("Items") }) },
) { innerPadding ->
LazyColumn(
contentPadding = innerPadding,
modifier = Modifier.fillMaxSize(),
) {
items(items) { item -> ItemRow(item, onOpen) }
}
}
}
Passing innerPadding as contentPadding, not as a Modifier.padding, keeps the same "scroll behind the bar" effect as clipToPadding="false" in Views.
For screens without a Scaffold, use the inset modifiers directly. For a form with a text field and a button at the bottom, the keyboard is the important one:
Column(
modifier = Modifier
.fillMaxSize()
.safeDrawingPadding()
.imePadding()
) {
// fields...
Spacer(Modifier.weight(1f))
Button(onClick = onSubmit, modifier = Modifier.fillMaxWidth()) {
Text("Save")
}
}
safeDrawingPadding() covers the system bars and the cutout. imePadding() moves the button above the keyboard. Apply each inset only once in the tree. If a parent already added the system bar padding, a child that adds it again gets a double gap.
Step 4: Keep it from coming back
Fixing every screen once is not enough. The next new screen will forget the insets unless something catches it.
- UI tests on both navigation modes. Our team already uses Espresso and Maestro. A flow that taps the bottom button on each main screen fails if the button sits under the navigation bar, because the tap lands on the system bar instead. Run the same flows on an emulator with gesture navigation and on one with three-button navigation.
- A screen template. New screens start from a base layout or a base composable that already handles insets. People copy what is already there, so make the right thing the easy thing.
- One reviewer question. In code review for any new screen, ask: "What happens at the top, the bottom and with the keyboard?" It takes ten seconds.
The target SDK bump itself goes in a separate pull request, after the inset fixes are merged. If something breaks after release, it is clear which change caused it, and the fixes do not depend on the bump. They work on older Android versions too.
Takeaways
- Apps that target API 36 cannot opt out of edge-to-edge. The
windowOptOutEdgeToEdgeEnforcementattribute is ignored. - Bump
targetSdkon a branch first and walk the app with both gesture and three-button navigation. Make a list before you fix anything. - Apply insets as padding on the views that need them, return them from listeners, and delete old hard-coded status bar margins.
- In Compose, use
innerPaddingfromScaffoldascontentPadding, and addimePadding()to forms. - Ship the inset fixes before the
targetSdkbump, and add UI tests that tap bottom buttons so the bug does not come back.
If you also work with Kotlin on Android, my post on Kotlin Flow for BLE responses covers another Android pattern from the same app.