Home > database >  Draw Activity below cutout in landscape
Draw Activity below cutout in landscape

Time:06-23

Similar to 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?

CodePudding user response:

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.

  • Related