I am trying to create a button where I can hide or show the status bar on my tablet.
I\'ve put in the onCreate
getWindow().addFlags(WindowManager.Lay
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);
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);
}
I've tried so many things.
Finally, It is the most suitable code to hide and show full screen mode.
private fun hideSystemUi() {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.R) {
window.setDecorFitsSystemWindows(true)
} else {
// hide status bar
getWindow().addFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN);
window.decorView.systemUiVisibility =
View.SYSTEM_UI_FLAG_IMMERSIVE or View.SYSTEM_UI_FLAG_HIDE_NAVIGATION
}
}
private fun showSystemUi() {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.R) {
window.setDecorFitsSystemWindows(false)
} else {
// Show status bar
window.clearFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN);
window.decorView.systemUiVisibility = SYSTEM_UI_FLAG_LAYOUT_STABLE
}
}
It Implemented it in this app : Android Breakdown.
Go to Videos(Bottom Bar) > Play Any Video > Toggle Fullscreen