Search code examples
androiduser-interfaceandroid-fragmentsandroid-fullscreen

Hide Status bar in a fragment or make the fragment full screen


I have a kotlin app with bottom navigation setup.

I currently have 5 fragments [ProfileFragment, SearchFragment, HomeFragment, SettingsFragment, WebViewFragment]

All of these are just blank fragments. But in my Profile Fragment, I'm showing off a panaroma widget in the top half of the page

Profile Page

I know about making my whole app full screen, but then, on other fragments, content will get hidden under notched displays. And by content, I mean my employer's logo, which he wants, without fail.

So, I tried another way. I made the app full screen and added padding wherever, there was content hiding under the notch. Now, there happen to be various phones, without notches. The content looked unusually padded down, because, well, there was no notch.

If I make adjustments for notched display, the non-notch displays will give issues. And vice-versa.

So, I figured, why not instead of making all activities in my app fullscreen, If I can stretch the ProfileFragment to cover the status bar, or hide the status bar, it'd be a perfect solution.

Is there a way to do either of the following?

  • Hide the status bar on the ProfileFragment
  • Stretch the fragment to the top of the screen
  • Make the fragment full screen, without cutting off the bottom navigation

Solution

  • You can try adding this code in your Activity:

    // Hide the status bar.
    window.decorView.systemUiVisibility = View.SYSTEM_UI_FLAG_FULLSCREEN
    // Remember that you should never show the action bar if the status bar is hidden, so hide that too if necessary.
    actionBar?.hide()
    

    More info here: https://developer.android.com/training/system-ui/status#kotlin