android:fitsSystemWindows
If true, adjusts the padding of this view to leave space for the system windows.
You can manually do that using WindowInsetsListener
.
ViewCompat.setOnApplyWindowInsetsListener(appBar) { view, windowInsets ->
val insets = windowInsets.getInsets(WindowInsetsCompat.Type.statusBars())
// Apply the insets as padding to the view. Here, set all the dimensions
// as appropriate to your layout. You can also update the view's margin if
// more appropriate.
view.updatePadding(insets.left, insets.top, insets.right, insets.bottom)
// Return CONSUMED if you don't want the window insets to keep passing down
// to descendant views.
WindowInsetsCompat.CONSUMED
}
please refer to:
https://developer.android.com/develop/ui/views/layout/edge-to-edge#system-bars-insets
https://developer.android.com/reference/android/view/View#attr_android:fitsSystemWindows