简体   繁体   中英

How to hide StatusBar in Android 4

How to hide StatusBar in Android 4:

Android 4中的StatusBar

Help me, please.

The bar that is shown in the image in your question is called the system bar.

On devices with no hardware buttons the system bar will always be displayed if user input occurs. You can call setSystemUiVisibility with the flags SYSTEM_UI_FLAG_HIDE_NAVIGATION and request the following window feature FLAG_FULLSCREEN via the Window . This should hide the system bar and make your view fullscreen as long as the user does not interact with the screen. If the user touches the screen the system bar will reappear to allow the user to use the home and back software keys.

If you have a view that the user will interact with but you want him not to be distracted by the system bar you can set the SYSTEM_UI_FLAG_LOW_PROFILE flag. This should dim the system bar and make it less distracting.

I agree with Janusz. You can not get 100% true full screen in Android 4.0.

Use the following to dim the notification bar (aka. status bar, system bar)

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

And use this to hide it

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

And, if I guess right, you are trying to achieve a "kiosk mode". You can get a little help with an app named "surelock". This blocks all the "home" and "back" actions.

If you wish a smooth experience without an intermediate "jerked" layout, here is the solution from API level 14.

final Window window = getWindow();
if (isFullScreen == true)
{
  window.addFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN);
  // This flag will prevent the status bar disappearing animation from jerking the content view
  window.addFlags(WindowManager.LayoutParams.FLAG_LAYOUT_NO_LIMITS);
  window.clearFlags(WindowManager.LayoutParams.FLAG_FORCE_NOT_FULLSCREEN);
}
else
{
  window.addFlags(WindowManager.LayoutParams.FLAG_FORCE_NOT_FULLSCREEN);
  window.clearFlags(WindowManager.LayoutParams.FLAG_LAYOUT_NO_LIMITS);
  window.clearFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN);
}

you can hide it. just use following api in OnCreate() method

requestWindowFeature(Window.FEATURE_NO_TITLE);

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM