1

I'm working on a full Landscape project. I need all the time to hide manually Navigation Bar. Opening new fragment all work perfectly calling following util on onResume method:

        fun systemUiVisibility(activity: Activity) {
        activity.window.decorView.systemUiVisibility = (
                View.SYSTEM_UI_FLAG_IMMERSIVE
                        or View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION
                        or View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN
                        or View.SYSTEM_UI_FLAG_HIDE_NAVIGATION
                        or View.SYSTEM_UI_FLAG_FULLSCREEN
                        or View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY
                )
        activity.window.addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON)
    }

When I open several items, such as Bottom sheet Fragment and others, the navigation bar is displayed again. Is there any way to permanently hide it anywhere?

DoctorWho
  • 1,044
  • 11
  • 34
  • are you calling in onWindowFocusChanged and onCreate before super.onCreate? – hemen Jul 17 '20 at 11:54
  • No I don't. write the answer below :-) – DoctorWho Jul 17 '20 at 12:01
  • it may be duplicate [first link](https://stackoverflow.com/questions/21164836/immersive-mode-navigation-becomes-sticky-after-volume-press-or-minimise-restore) and [second link](https://stackoverflow.com/questions/21724420/how-to-hide-navigation-bar-permanently-in-android-activity) – hassan moradnezhad Jul 17 '20 at 12:08
  • it's not duplicate. Opening BottomSHeetFragment don't work – DoctorWho Jul 17 '20 at 12:34

1 Answers1

0

In my case, it was enough to override these two methods:

override fun onResume()
{
    super.onResume()
    window.decorView.systemUiVisibility = View.SYSTEM_UI_FLAG_HIDE_NAVIGATION or View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY
}

override fun onWindowFocusChanged(hasFocus: Boolean)
{
    super.onWindowFocusChanged(hasFocus)
    window.decorView.systemUiVisibility = View.SYSTEM_UI_FLAG_HIDE_NAVIGATION or View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY
}

but I am not sure if it will protect You from every scenario.

iknow
  • 8,358
  • 12
  • 41
  • 68