1

I am trying to make the navigation bar disappear from my app. The requirement is that I need to have the status bar and action bar. Only the navigation bar should be disappear.

I have this code in the activity class

override fun onWindowFocusChanged(hasFocus: Boolean) {
    super.onWindowFocusChanged(hasFocus)

    window.decorView.apply {
        systemUiVisibility = View.SYSTEM_UI_FLAG_HIDE_NAVIGATION
    }
}

This code is making the navigation bar disappear. But when the activity window loses focus, the navigation bar is reappearing.

When activity is shown, the navigation bar is not appearing. enter image description here

When activity window loses focus, the navigation bar is appearing. For eg., when an alert box appears.

enter image description here

Looking forward to the help.


Edit: Another example -- when application button is pressed. Native Google Play app is showing full screen whereas my app is displaying navigation bar

enter image description here

Sethuraman Srinivasan
  • 1,528
  • 1
  • 20
  • 34
  • The topmost window is what controls the status and navigation bar visibility. Is there a reason you aren't using the same flags on your dialog's window? – ianhanniballake Jul 05 '22 at 03:49
  • @ianhanniballake I don't have a separate class for dialog window. I just use a simple one https://stackoverflow.com/a/2115770/2579739. – Sethuraman Srinivasan Jul 05 '22 at 04:15
  • @ianhanniballake But the issue is dialog window is just an example. When a permission dialog window shows up, I get the same issue. – Sethuraman Srinivasan Jul 05 '22 at 04:16
  • 1
    `Dialog` has a `window` property you can access, same as you do in your Activity code you've posted. You'll never, ever be able to hide the status bar or navigation bar when a permission dialog window shows up, sorry: you don't own that window. – ianhanniballake Jul 05 '22 at 05:09
  • @ianhanniballake I agree with you. Let me provide another example: when application button is pressed. Native Google Play app is showing full screen whereas my app is displaying navigation bar. Attached an image to the original post for reference – Sethuraman Srinivasan Jul 08 '22 at 03:28
  • That's not using window flags at all. That's just the Google Play app going [edge to edge](https://developer.android.com/training/gestures/edge-to-edge). – ianhanniballake Jul 08 '22 at 03:46

1 Answers1

1

Try this:

//puts windows in fullscreen
fun fullScreen(view: View, window: Window) {
    WindowCompat.setDecorFitsSystemWindows(window, false)
    WindowInsetsControllerCompat(window, view).let { controller ->
        controller.hide(WindowInsetsCompat.Type.statusBars())
        controller.hide(WindowInsetsCompat.Type.navigationBars())
        WindowInsetsControllerCompat.BEHAVIOR_SHOW_TRANSIENT_BARS_BY_SWIPE.also { controller.systemBarsBehavior = it }

    }
}

And also if this does not work, you can try using NoActionBar Theme and then create your own action bar (navigation bar), which in turn can be altered in any way you like.

Haris
  • 372
  • 3
  • 16
  • When the keyboard is popping up, it's not pushing the view to the top. The keyboard is overlapping the view. That's the only issue I am facing with the code – Sethuraman Srinivasan Jul 08 '22 at 02:00
  • Maybe releasing the bottom constraint of the view and keeping the top constraint will help. Try it. – Haris Jul 08 '22 at 05:55