title: Android Hide Navigation Bar/Stay in Immersive Mode when Button clicked
body: <p>What seems like a really simple thing is causing me a few issues.  I have looked at the solutions from:</p>
  
  <p><a href="https://stackoverflow.com/questions/27115600/android-hide-navigation-bar-stay-in-immersive-mode-with-soft-keyboard-appearance">Android Hide Navigation Bar/Stay in Immersive Mode with Soft Keyboard Appearance</a>.</p>
  
  <p>I have a simple activity with a ImageButton on.  I want to be in Immersive Mode.  I call the following method onCreate.</p>
  
  <p><strong>Issue</strong>
  The first click on the screen always brings up the navigation bar and does not fire the click handler.  Is there a simple / less hacky way to stop this</p>
  
  <pre><code> public void hideNavigationBar()
          {
              final View decorView = getWindow().getDecorView();
  
              int uiOptions = View.SYSTEM_UI_FLAG_HIDE_NAVIGATION
                      | View.SYSTEM_UI_FLAG_FULLSCREEN;
              decorView.setSystemUiVisibility(uiOptions);
  
              decorView.setOnSystemUiVisibilityChangeListener (new View.OnSystemUiVisibilityChangeListener() {
                  @Override
                  public void onSystemUiVisibilityChange(int visibility) {
                      if ((visibility &amp; View.SYSTEM_UI_FLAG_FULLSCREEN) == 0) {
                          decorView.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);
                      }
                  }
              });
          }
  </code></pre>