2

This has been asked many times: How to hide status bar permanently in android? Android ICS hide System bar Hide permanent system Bar Android But most of the times answers dont work or only hide until the users swips with his finger.

requestWindowFeature(Window.FEATURE_NO_TITLE);
getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
                        WindowManager.LayoutParams.FLAG_FULLSCREEN);

This resolves into the application crashing.

getWindow().addFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN);

This hides it temporarily.

    window.decorView.systemUiVisibility =
        View.SYSTEM_UI_FLAG_LAYOUT_STABLE 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

Setting the systemUIVisiblity has exactly the same effect.

    val windowInsetsController =
        ViewCompat.getWindowInsetsController(window.decorView) ?: return
    // Configure the behavior of the hidden system bars
    windowInsetsController.systemBarsBehavior =
        WindowInsetsControllerCompat.BEHAVIOR_SHOW_TRANSIENT_BARS_BY_SWIPE
    // Hide both the status bar and the navigation bar
    windowInsetsController.hide(WindowInsetsCompat.Type.systemBars())

This does not seem to be doing anything, but if it would, it would probably also just hide until the swipe.

If have tried calling these code blocks repeatively on different events:

val screenText : TextView = findViewById(R.id.textView5);
screenText.setOnClickListener {
    hideSystemUI()
}

Creating a TextView and calling the code blocks on click.

    window.decorView.setOnSystemUiVisibilityChangeListener { visibility ->
        // Note that system bars will only be "visible" if none of the
        // LOW_PROFILE, HIDE_NAVIGATION, or FULLSCREEN flags are set.
        if (visibility and View.SYSTEM_UI_FLAG_FULLSCREEN == 0) {
            // TODO: The system bars are visible. Make any desired
            // adjustments to your UI, such as showing the action bar or
            // other navigational controls.
            hideSystemUI()
        } else {
            // TODO: The system bars are NOT visible. Make any desired
            // adjustments to your UI, such as hiding the action bar or
            // other navigational controls.
        }
    }

This code snippet from https://developer.android.com/training/system-ui/visibility

But these work hacky, and if you are fast you can still expand the status bar. The navigation bar will always appear after swiping.

Why do I want to make these bars disappear? Because I am writing a launcher. It should look similar to the Samsung Kids. The user should be prohibited to change anything in the system settings until some password is given in. How would one do that with these limitations?

Marcin Orlowski
  • 72,056
  • 11
  • 123
  • 141
janos_
  • 21
  • 4
  • 3
    Swiping the edge of the screen to make the bars appear is a system gesture, none of the immersive mode flags allow you to block that - which is good, because it would be a really frustrating experience if an app prevented things like using the home button. I don't know how Samsung Kids works specifically, but I wouldn't be surprised if Samsung has some system hooks for their own apps that allow them to override the usual UI, and basically "lock" the user into a particular app (or account, or however they're doing it). But those aren't the kinds of privileges you'd give a random app – cactustictacs Jan 01 '22 at 18:35
  • @cactustictacs what you are saying is correct. In my case I want to have an app that runs constantly in kiosk mode (basically same idea), now this app should be running 24/7 and can only get out of kiosk mode using a pin code or password to access it. Problem is that there is no proper explanation on how to achieve this in more recent android versions, as most explanations are like 7 years old and thus no longer function for the newer versions. There are apps like Fully Kiosk and such that are able to achieve this, so it must be possible, but so far no clue how to do it. – Billy Cottrell Jan 12 '22 at 11:21
  • Well from a brief look around Fully Kiosk's FAQ (https://www.fully-kiosk.com/en/#faq-android12) they're using "some moderate hacks" and exploiting some loopholes - looks like Android 12 has patched a lot of it out (and they're telling people to block OS upgrades for that reason). Their instructions for completely hiding the system bars on Android 10 and below involve the user installing ADB, enabling USB debugging and running some privilege elevation commands. You *might* get someone on here who knows about that hacky stuff, but you might be better asking on XDA Developers or something though – cactustictacs Jan 12 '22 at 19:27

2 Answers2

0

I have been using this, and it has been working fine so far. Running it just after setContentView().

    if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.LOLLIPOP) {
        window.setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
            WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS)
    }
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.R) {
        window.insetsController?.hide(WindowInsets.Type.statusBars())
    }
hayzie101
  • 23
  • 5
  • 1
    I have tried to apply this, but statusbar is not permanently hidden, by swiping at the top downwards shows the statusbar again. Also FLAG_FULLSCREEN is deprecated in newer versions FYI. – Billy Cottrell Jan 12 '22 at 11:21
0

Works on android 11 Notice that the method only works.If the android os is a customize image and you have the privilege to change the os source code underpath:

hide nevigation bar from SystemUI in custom android11 os

see the source code https://android.googlesource.com/platform/prebuilts/fullsdk/sources/android-30/+/refs/heads/androidx-wear-wear-ongoing-release/com/android/systemui/statusbar/NavigationBarController.java

frameworks\base\packages\SystemUI\src\com\android\systemui\statusbar\phone\NavigationBarController.java

@Override
    public void onDisplayRemoved(int displayId) {
        removeNavigationBar(displayId);
    }


Using view to set flag cannot work properly because when you switch window or app the nav bar will appear again

and it you can easily remove navigationbar or others

jason yu
  • 21
  • 5