Support Edge to Edge in the Android apps



This article is about adding Edge-to-Edge support in the Android applications. We are going to understand the concept with help of questions and finally understand how to code to achieve the required support.

What is Edge-to-Edge?

Expanding our apps contents to display app content across the entire screen. By default content of the app is between status bar and navigation bar (collectively called as System Bars)    .

Why should we add this functionality?

  • Helps in letting app provide immersive experience to the user. This is an important feature for the apps supporting “image viewer” or “video viewer” or "games" app.
  • Provides more area to the app to show the content.

Steps to achieve edge to edge

1. Layout your app full-screen.

This method tells the window that the content of the app will expand to full screen. Once this is called the app content view will be drawn from the edges. Check the screenshot below.

Notice that the top text view and bottom buttons are behind the system bars.


2. Change the system bar colors and transparency.


Now that content is drawn behind system bars we need to update the bars colors so that the app content is visible. For this we will set the colours of status bar and navigation bar to transparent. Note this is only required for API 29 and above as the system bars have a translucent scrim behind system bars. For API 28 level and below the system bars is by default transparent. Check the below screenshot after making system bars transparent.

Notice that the top text view and bottom buttons are behind system bars and color is set to transparent.



3. Handle any visual overlaps.



The system bars are made transparent. Even if they are transparent they are part of the hierarchy and can consume the touch. So in the scenario where we have an app widget that intersects with system bars it will not allow the widget to handle the user touch. Hence blocking the usage of that widget. Check the screen added in above section where bottom buttons are overlapped by navigation bar.

To prevent this from happening the android system has a concept of insets which provides the required space taken by the system bars. We can use this space value to position the view such that it can handle the user touch.

There are different types of insets to represent the space taken by the different window components. A few of them are:
  • System bars (status bar + navigation bar + caption bar)
  • Display cutout (black cut outs see at the top or bottom of the device)
  • System gesture inset
Notice that top text view is moved below the status bar and bottom buttons are moved above navigation bar.


Resources:

https://developer.android.com/training/gestures/edge-to-edge

Comments

Popular posts from this blog

Fragment Lifecycle

AndroidManifest

Activity Lifecycle