gorootde
gorootde

Reputation: 4073

Android ICS hide System bar

I am trying to hide / minimize the system bar in Android 4.0.3. At the moment I'am doing

getWindow().getDecorView().setSystemUiVisibility(View.SYSTEM_UI_FLAG_HIDE_NAVIGATION);

in the onCreate event of my activity. As soon as the user touches the screen the bar will show up again. According to other STO threads, this behavior can not be circumvented. My idea is to catch any touch event on my view, and re-hide the bar immediately after it is shown. Running the code shown above in the click handler has no effect. How to achieve a (hardly) hidden bar?

Upvotes: 0

Views: 2505

Answers (2)

PiyushMishra
PiyushMishra

Reputation: 5773

You can't hide it but you can simply disable it, except home. Try this link. . Using SYSTEM_UI_FLAG_LOW_PROFILE you can dim your system bar and using onWindowFocusChanged() can take the focus and collapse it.

Upvotes: 0

Pascal
Pascal

Reputation: 16631

I will not talk about the 'why', just about the 'how' :-)

So, about

getWindow().getDecorView().setSystemUiVisibility(View.SYSTEM_UI_FLAG_HIDE_NAVIGATION);

This will not affect tablet devices, which use a system bar rather than a separate navigation and status bars.

On Tablet, you could try (API Level 14 onward)

myView.setSystemUiVisibility(View.SYSTEM_UI_FLAG_LOW_PROFILE);

To detect the event, I think you could use this to catch the event:

myView.setOnSystemUiVisibilityChangeListener(
   new OnSystemUiVisibilityChangeListener()
      {
      public void onSystemUiVisibilityChange(int visibility)
      {
         if (visibility == View.SYSTEM_UI_FLAG_VISIBLE) {
            // TODO whatever you want
         }
         else {
            // TODO what to do in the other case
         }
      }
   }
);

More generally, here is an additional advice from 'Professional Android 4 Application development'

It’s generally good practice to synchronize other changes within your UI with changes in navigation visibility. For example, you may choose to hide and display the Action Bar and other navigational controls based on entering and exiting “full screen mode.” You can do this by registering an OnSystemUiVisibilityChangeListener to your View — generally, the View you are using to control the navigation visibility

.

Upvotes: 1

Related Questions