I am trying to make my app switch between true full screen (no status bar, no action bar) and "normal mode" (action bar and status bar). For that, I've set up an action bar in overlay mode and I allow user to toggle both the action bar and the status bar on:
getWindow().addFlags(WindowManager.LayoutParams.FLAG_FORCE_NOT_FULLSCREEN);
getWindow().clearFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN);
actionBar.show();
..and off:
getWindow().addFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN);
getWindow().clearFlags(WindowManager.LayoutParams.FLAG_FORCE_NOT_FULLSCREEN);
actionBar.hide();
This works OK with only one exception: the actual layout is resized whenever either of these actions takes place. Well, there is another flag to account apparently just for that, and so I add to my onCreate()
:
getWindow().addFlags(WindowManager.LayoutParams.FLAG_LAYOUT_NO_LIMITS);
OK, now the resizing is no longer an issue, however now my action bar is half obscured by the status bar whenever both are on:
Is there something I'm missing? How can I make the action bar to properly display right below the status bar?
After trial and error, I've found a solution. This hides both action bar and status bar without causing the image to resize.
private void toggleFullscreen(boolean on) {
ActionBar actionBar = getActionBar();
View decorView = getWindow().getDecorView();
if (on) {
decorView.setSystemUiVisibility(
View.SYSTEM_UI_FLAG_LAYOUT_STABLE
| View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN
| View.SYSTEM_UI_FLAG_FULLSCREEN);
actionBar.hide();
}
else {
decorView.setSystemUiVisibility(
View.SYSTEM_UI_FLAG_LAYOUT_STABLE
| View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN);
actionBar.show();
}
}