I have an app, where I hide programatically StatusBar. After I've pressed the Popupmenu button or even Toolbar layout Status Bar appears "itself". I have no idea how to prevent such situations to happend. I'm using KitKat and all of actions of hidding or showing Statusbar are handled in Activity.
OnCreate() - listener invoked after show/hide
statusBarView = getWindow().getDecorView();
statusBarFlag = false;
statusBarView.setOnSystemUiVisibilityChangeListener(new View.OnSystemUiVisibilityChangeListener() {
@Override
public void onSystemUiVisibilityChange(int visibility) {
if ((visibility & View.SYSTEM_UI_FLAG_FULLSCREEN) == 0) {
// TODO: The system bars are visible. Make any desired
if (!statusBarFlag){
hideStatusBar();
}
}
}
});
OnResume()
public void onResume() {
super.onResume();
if(!statusBarFlag){
hideStatusBar();
}
SelectItem(mDrawerPosition.groupPosition, mDrawerPosition.childPosition);
}
OnWindowFocusChanged()
public void onWindowFocusChanged(boolean hasFocus) {
super.onWindowFocusChanged(hasFocus);
if(hasFocus){
if(statusBarFlag)
showStatusBar();
} else {
hideStatusBar();
}
Show/Hide methods
private void hideStatusBar(){
statusBarFlag=false;
statusBarView.setSystemUiVisibility(View.SYSTEM_UI_FLAG_FULLSCREEN
| View.SYSTEM_UI_FLAG_HIDE_NAVIGATION
| View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN);
}
private void showStatusBar(){
statusBarFlag=true;
statusBarView.setSystemUiVisibility(View.SYSTEM_UI_FLAG_VISIBLE
| View. SYSTEM_UI_FLAG_LAYOUT_STABLE
| View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN
| View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION);
}
where statusBarFlag=fale means that Bar is not visible and true where is. I'm using it to synchronize status of StatusBar with my trigger (item) Checkbox in Popup Menu.