2 Replies Latest reply on Apr 1, 2014 12:08 PM by Adel Sari

    How can I hide the Navigation bar (Back, Home, End Session) while my application is visible?

      How can I hide the Navigation bar (Back, Home, End Session) while my application is visible?

        • Re: How can I hide the Navigation bar (Back, Home, End Session) while my application is visible?

          Add the following method to your Activity and invoke from onResume.


          The only part different from normal Android is the addition of the flag 0x4 that tells the OS to keep the navigation bar hidden.


          private void setFullScreen(final boolean fullscreen) {

                  // Hide/show the system bar

                  Window window = getWindow();

                  window.setFlags(fullscreen ?

                          WindowManager.LayoutParams.FLAG_FULLSCREEN : 0,

                          WindowManager.LayoutParams.FLAG_FULLSCREEN);

           

                  if (fullscreen) {

                      // Keep the system bar hidden in full screen mode

                      window.getDecorView().setOnSystemUiVisibilityChangeListener(new OnSystemUiVisibilityChangeListener() {

                          @Override

                          public void onSystemUiVisibilityChange(int visibility) {

                              if ((visibility & View.SYSTEM_UI_FLAG_HIDE_NAVIGATION) != 0) {

                                  getWindow().setFlags(

                                          WindowManager.LayoutParams.FLAG_FULLSCREEN,

                                          WindowManager.LayoutParams.FLAG_FULLSCREEN);

                              }

                              else {

                                  getWindow().getDecorView().setSystemUiVisibility(

                                          View.SYSTEM_UI_FLAG_HIDE_NAVIGATION | 0x4);

                              }

                          }

                      });

                  }

                  else {

                      window.getDecorView().setOnSystemUiVisibilityChangeListener(null);

                  }

                  window.getDecorView().setSystemUiVisibility(

                          fullscreen ? (View.SYSTEM_UI_FLAG_HIDE_NAVIGATION | 0x4) : 0);

              }