Issue
Before, to enable immersive fullscreen mode, you'd have to use setSystemUiVisibility
, like so:
getWindow().getDecorView().setSystemUiVisibility(View.SYSTEM_UI_FLAG_LAYOUT_STABLE
| View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION
| View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN
| View.SYSTEM_UI_FLAG_HIDE_NAVIGATION
| View.SYSTEM_UI_FLAG_FULLSCREEN
| View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY);
As of API 30, it's deprecated, so what's the workaround?
Solution
For compatibility, use WindowCompat
and WindowInsetsControllerCompat
. You'll need to upgrade your gradle dependency for androidx.core
to at least 1.6.0-alpha03
so that there will be support for setSystemBarsBehavior
on SDK < 30. mainContainer
is the top-level ConstraintLayout
in my activity.
private fun hideSystemUI() {
WindowCompat.setDecorFitsSystemWindows(window, false)
WindowInsetsControllerCompat(window, mainContainer).let { controller ->
controller.hide(WindowInsetsCompat.Type.systemBars())
controller.systemBarsBehavior = WindowInsetsControllerCompat.BEHAVIOR_SHOW_TRANSIENT_BARS_BY_SWIPE
}
}
private fun showSystemUI() {
WindowCompat.setDecorFitsSystemWindows(window, true)
WindowInsetsControllerCompat(window, mainContainer).show(WindowInsetsCompat.Type.systemBars())
}
You can find out more information about WindowInsets
by watching this YouTube video
EDIT:
I didn't consider display cutouts or in-display cameras in this answer previously. In the app theme style, i added the following to display my content above the cutout (to the top of the screen when in portrait mode):
<item name="android:windowLayoutInDisplayCutoutMode">shortEdges</item>
You can read more at this link: Display Cutout
Answered By - James
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.