Calling enableEdgeToEdge
encapsulates the logic needed to be truly
backward compatible and is therefore the recommended way to set up an
edge-to-edge display. Refer to the Compose and Views documentation
instead of this guide for the modern way to go edge-to-edge using
enableEdgeToEdge
.
While not recommended, if your app must manually set up an edge-to-edge display you can follow these steps:
- Call
WindowCompat.setDecorFitsSystemWindows(window, false)
. - Set the system bars to transparent.
- Handle insets.
Lay out your app in full screen
Use WindowCompat.setDecorFitsSystemWindows(window, false)
to lay out your app behind the system bars, as shown in the following code
example:
Kotlin
override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) WindowCompat.setDecorFitsSystemWindows(window, false) }
Java
@Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); WindowCompat.setDecorFitsSystemWindows(getWindow(), false); }
Change the color of the system bars
When manually creating an edge-to-edge layout for Android 14 and older, your app must also make the system bars transparent.
You can edit the themes.xml
file to set the color of the status and navigation
bar as transparent and change the status bar icon color.
<!-- values-v29/themes.xml -->
<style name="Theme.MyApp">
<item name="android:navigationBarColor">
@android:color/transparent
</item>
<!-- Optional: set to transparent if your app is drawing behind the status bar. -->
<item name="android:statusBarColor">
@android:color/transparent
</item>
<!-- Optional: set for a light status bar with dark content. -->
<item name="android:windowLightStatusBar">
true
</item>
</style>
You can use the WindowInsetsControllerCompat
API instead of
theme.xml
to control the status bar's content color. To do so, use the
setAppearanceLightNavigationBars()
function, passing in true
to change the foreground color of the navigation to
a light color or false
to revert to the default color.
Kotlin
val windowInsetsController = ViewCompat.getWindowInsetsController(window.decorView) windowInsetsController?.isAppearanceLightNavigationBars = true
Java
WindowInsetsControllerCompat windowInsetsController = ViewCompat.getWindowInsetsController(getWindow().getDecorView()); if (windowInsetsController == null) { return; } windowInsetsController.setAppearanceLightNavigationBars(true);
Handle insets
Finally, your app must to handle insets so that critical UI avoids the system bars and display cutout. Refer to the Compose and Views documentation to learn how to handle insets.