Android: show/hide status bar/power bar
I know its a very old question, but just in case anyone lands here looking for the newest supported way to hide status bar on the go programmatically, you can do it as follows:
window.insetsController?.hide(WindowInsets.Type.statusBars())
and to show it again:
window.insetsController?.show(WindowInsets.Type.statusBars())
For Some People, Showing status bar by clearing FLAG_FULLSCREEN may not work,
Here is the solution that worked for me, (Documentation) (Flag Reference)
Hide Status Bar
// Hide Status Bar
if (Build.VERSION.SDK_INT < 16) {
getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
WindowManager.LayoutParams.FLAG_FULLSCREEN);
}
else {
View decorView = getWindow().getDecorView();
// Hide Status Bar.
int uiOptions = View.SYSTEM_UI_FLAG_FULLSCREEN;
decorView.setSystemUiVisibility(uiOptions);
}
Show Status Bar
if (Build.VERSION.SDK_INT < 16) {
getWindow().clearFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN);
}
else {
View decorView = getWindow().getDecorView();
// Show Status Bar.
int uiOptions = View.SYSTEM_UI_FLAG_VISIBLE;
decorView.setSystemUiVisibility(uiOptions);
}
Do you have the fullscreen theme set in the manifest?
android:theme="@android:style/Theme.NoTitleBar.Fullscreen"
I don't think you'll be able to go fullscreen without this.
I would use the following to add and remove the fullscreen flag:
// Hide status bar
getWindow().addFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN);
// Show status bar
getWindow().clearFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN);
used for kolin in android for hide status bar in kolin no need to used semicolon(;) at the end of the line
window.addFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN)
in android using java language for hid status bar
getWindow().addFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN);