How to hide Navigation Bar permanently in Jelly Bean (before KitKat) in Android Activity?

2.3k views Asked by At

I made a Full-Screen app for android which hides both Navigation Bar & Status Bar that supports API 16 (starting from Jelly Bean).. I know that if I want to hide both Navigation Bar & Status Bar starting from KitKat I can use the following code:

getWindow().getDecorView().setSystemUiVisibility(
                View.SYSTEM_UI_FLAG_LAYOUT_STABLE
                        | View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION
                        | View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN
                        | View.SYSTEM_UI_FLAG_HIDE_NAVIGATION
                        | View.SYSTEM_UI_FLAG_FULLSCREEN
                        | View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY);

But that code doesn't work for Jelly Bean, it hides the bars only once and they reappear once you touch the screen. So I know that the following code supports Jelly Bean but it only hides the Status Bar:

getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
                WindowManager.LayoutParams.FLAG_FULLSCREEN);

Can anyone show me the way to hide the Navigation Bar as well on Jelly Bean permanently?

1

There are 1 answers

3
pelotasplus On

Try hiding statusbar/navigation bar once again after it appears on the screen.

Here is information how to listen for UI changes:

https://developer.android.com/training/system-ui/visibility.html

Relevant part:

View decorView = getWindow().getDecorView();
decorView.setOnSystemUiVisibilityChangeListener
        (new View.OnSystemUiVisibilityChangeListener() {
    @Override
    public void onSystemUiVisibilityChange(int visibility) {
        if ((visibility & View.SYSTEM_UI_FLAG_FULLSCREEN) == 0) {
            // system bars are visible
            // hide them again, maybe with some delay?
        }
    }
});