I am encountering difficulty maintaining immersive mode throughout my activity.
I have an activity consisting of various fragments. Within the initial (main) fragment, screen rotation is enabled. However, in the other fragment, screen rotation is disabled. Upon the activity's creation, the start fragment is displayed in immersive mode (fullscreen). When transitioning to the other fragment, the activity remains in immersive mode. However, upon navigating back to the start fragment, although the navigation bar is not visible, but the view does not return to fullscreen.
In the activity I have the following function which will be called when a fragment will resume (Inside th)
Activity:
fun setFullScreen() {
this.requestedOrientation = ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED
val windowInsetsController = WindowCompat.getInsetsController(window, window.decorView)
windowInsetsController.systemBarsBehavior = WindowInsetsControllerCompat.BEHAVIOR_SHOW_TRANSIENT_BARS_BY_SWIPE
windowInsetsController.hide(WindowInsetsCompat.Type.systemBars())
}
Inside the fragments:
override fun onResume() {
super.onResume()
val activity = activity as MainActivity
activity.setFullScreen()
}
The problem is, as I wrote above, is that the navigation bar is hide, but the layout does not fit. The following picture shows the result after the return to the start fragment. Is it possible to resize the layout, so that the BottomNavigationView covers the navigation bar? 
The problem was, that I used old code inside the Fragment
By removing this code, it works fine.