0

In a certain activity in my app I am hiding the navigation bar since that activity is full screen. To hide the navigation bar I am using the following code:

    private void hideSystemUI() {
        // Enables regular immersive mode.
        // For "lean back" mode, remove SYSTEM_UI_FLAG_IMMERSIVE.
        // Or for "sticky immersive," replace it with SYSTEM_UI_FLAG_IMMERSIVE_STICKY
        View decorView = getWindow().getDecorView();
        decorView.setSystemUiVisibility(
                View.SYSTEM_UI_FLAG_IMMERSIVE
                        | View.SYSTEM_UI_FLAG_HIDE_NAVIGATION // hide nav bar
                        | View.SYSTEM_UI_FLAG_FULLSCREEN
        );
    }

This code works fine until the user swipes up the navigation bar. It then stays there. What I want is that it hides again after 2 seconds or so. Is there a way to achieve this?

I appreciate any help!

Kaiser
  • 606
  • 8
  • 22

1 Answers1

0

You can Use this code:

private FullScreenListener fullScreenListener = new FullScreenListener();
private void initUiFlags() {
    int flags = View.SYSTEM_UI_FLAG_VISIBLE;

    flags |= View.SYSTEM_UI_FLAG_LAYOUT_STABLE
            | View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN
            | View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION;

    View decorView = getWindow().getDecorView();
    decorView.setSystemUiVisibility(flags);
    decorView.setOnSystemUiVisibilityChangeListener(fullScreenListener);
}
Nayan Sarder
  • 512
  • 1
  • 3
  • 18