Draw Activity below cutout in landscape

610 Views Asked by At

Similar to Activity not extended below the cutout in landscape, but the answer there is limiting.

In landscape, the camera cutout is on the left. I used

<item name="android:windowLayoutInDisplayCutoutMode">shortEdges</item>

to stretch the background color below it:

enter image description here

I would like to actually render some elements (like the title panel) below the cutout area. Is this possible, without entering full screen?

1

There are 1 best solutions below

0
On BEST ANSWER

First you need set window_flags, we can use WindowCompat from androidx.appcompat.

Add this in your activity onCreate. This asks the system to lay out your activity edge to edge.

WindowCompat.setDecorFitsSystemWindows(window, false)

Then you need to add necessary padding to your content that should not be blocked. For example, here I have added padding to my AppBar. This is achieved by setting an inset listener callback on any view once.

binding.topBar.setOnApplyWindowInsetsListener { v, insets ->

    val compatInset = WindowInsetsCompat.toWindowInsetsCompat(insets)
            .getInsets(WindowInsetsCompat.Type.systemBars())
   binding.topBar.updatePadding(left = compatInset.left, top = compatInset.top, right = compatInset.right)

    return@setOnApplyWindowInsetsListener insets
}

You mostly only want to deal with systemBars as cutouts usually change the systemBar's size. Unless you are targeting a specific device cutout.