Disclaimer:
This is complementary answer as the accepted answer is valid without deprecation > till API level 30 because the system
visibility flags are deprecated as of API level 30.
setDecorFitsSystemWindows()
implements edge-to-edge to your app (i.e. the app will be expanding its content to extend across the entire screen to cover both the system status & navigation bars)
And this can be implemented in the activity with:
WindowCompat.setDecorFitsSystemWindows(window, false)
Now the remaining part is to avoid the overlapping with the system navigation bar:
As per documentation:
You can address overlaps by reacting to insets, which specify which
parts of the screen intersect with system UI such as the navigation
bar or the status bar. Intersecting can mean simply being displayed
above the content, but it can also inform your app about system
gestures, too.
So, We need to handle the insets for API level 30+ to avoid the overlapping between the app and the bottom navigation bar:
/*
* Making the Navigation system bar not overlapping with the activity
*/
if (Build.VERSION.SDK_INT >= 30) {
// Root ViewGroup of my activity
val root = findViewById<ConstraintLayout>(R.id.root)
ViewCompat.setOnApplyWindowInsetsListener(root) { view, windowInsets ->
val insets = windowInsets.getInsets(WindowInsetsCompat.Type.systemBars())
// Apply the insets as a margin to the view. Here the system is setting
// only the bottom, left, and right dimensions, but apply whichever insets are
// appropriate to your layout. You can also update the view padding
// if that's more appropriate.
view.layoutParams = (view.layoutParams as FrameLayout.LayoutParams).apply {
leftMargin = insets.left
bottomMargin = insets.bottom
rightMargin = insets.right
}
// Return CONSUMED if you don't want want the window insets to keep being
// passed down to descendant views.
WindowInsetsCompat.CONSUMED
}
}
Check documentation for more info.
Extra cent:
- If you're going to use
<item name="android:windowTranslucentStatus">true</item>
for lower API levels, then you have to override the themes/styles in API-30; i.e. to have a res\values-v30\themes.xml
with the default style (of course without windowTranslucentStatus
)