androidandroid-layoutandroid-statusbar

Android: Implementing edge-to-edge while hiding top/status bar


I'm currently trying to implement edge-to-edge for an Android application and have done it successfully using the official guide (https://developer.android.com/training/gestures/edge-to-edge#lay-out-in-full-screen).

But the issue here is that I want to hide the top/status bar when edge-to-edge is implemented. I have tried hiding the status bar by defining <item name="android:windowFullscreen">true</item> in the main theme of the app but that pushes the contents below the top/status bar unfortunately and even adding a negative padding doesn't resolve the issue. Also, I have seen this being implemented correctly in Google Camera (for the settings option)

What's the right way to hide the status bar while implementing edge-to-edge (assuming we want to add clickable contents such as a button below it)?


Solution

  • Add this to the activity that has edge-to-edge enabled.

    <item name="android:windowLayoutInDisplayCutoutMode" tools:targetApi="o_mr1">always</item>
    

    This prevents the activity's contents from being pushed below the status bar because it forces that space to be always available.