Skip to content

Instantly share code, notes, and snippets.

@Reacoder
Created June 6, 2014 07:07
Show Gist options
  • Save Reacoder/67c009dd9680b7ca3ad9 to your computer and use it in GitHub Desktop.
Save Reacoder/67c009dd9680b7ca3ad9 to your computer and use it in GitHub Desktop.
Show or hide status bar.
private void hideStatusBar() {
if (Build.VERSION.SDK_INT < 16) {
hideStatusBarLowVersion();
} else {
hideStatusBarHighVersion();
}
}
private void showStatusBar() {
if (Build.VERSION.SDK_INT < 16) {
showStatusBarLowVersion();
} else {
showStatusBarHighVersion();
}
}
@TargetApi(Build.VERSION_CODES.ICE_CREAM_SANDWICH)
private void showStatusBarHighVersion() {
View decorView = getWindow().getDecorView();
int uiOptions = View.SYSTEM_UI_FLAG_VISIBLE;
decorView.setSystemUiVisibility(uiOptions);
}
private void showStatusBarLowVersion() {
getWindow().addFlags(
WindowManager.LayoutParams.FLAG_FORCE_NOT_FULLSCREEN);
getWindow().clearFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN);
}
private void hideStatusBarLowVersion() {
getWindow().addFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN);
getWindow().clearFlags(
WindowManager.LayoutParams.FLAG_FORCE_NOT_FULLSCREEN);
}
@TargetApi(Build.VERSION_CODES.JELLY_BEAN)
private void hideStatusBarHighVersion() {
View decorView = getWindow().getDecorView();
int uiOptions = View.SYSTEM_UI_FLAG_FULLSCREEN;
decorView.setSystemUiVisibility(uiOptions);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment