I am creating an application in which a warning appears when you press a specific button. The status bar should be hidden, so I have a method in my activity:
private void hideStatusBar(){ if (Build.VERSION.SDK_INT < 16){ getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN); } else { View decorView = getWindow().getDecorView(); int uiOptions = View.SYSTEM_UI_FLAG_FULLSCREEN; decorView.setSystemUiVisibility(uiOptions); } }
I call this method in the onCreate method and it works fine until a warning dialog appears. As soon as the warning dialog appears, a status bar will appear. I tried the following:
alertDialog.show(); hideStatusBar();
which did not work. Then I redefined the onWindowFocusChanged method for my activity:
public void onWindowFocusChanged(boolean hasFocus) { super.onWindowFocusChanged(hasFocus); hideStatusBar(); }
which makes the background of the status bar transparent, but still does not hide it. Is there a way to keep the status bar hidden when a warning dialog is displayed?
source share