My app runs in fullscreen (immersive mode).
The status bar is hidden at the top.
On some Samsung phones, there is a stylus pen. If the pen is removed, the status bar re-appears and won't go away.
I tried adding a listener for this event but it doesn't get called.
View decorView = getActivity().getWindow().getDecorView();
decorView.setOnSystemUiVisibilityChangeListener
(new View.OnSystemUiVisibilityChangeListener()
{
@Override
public void onSystemUiVisibilityChange(int visibility) {
// Note that system bars will only be "visible" if none of the
// LOW_PROFILE, HIDE_NAVIGATION, or FULLSCREEN flags are set.
if ((visibility & View.SYSTEM_UI_FLAG_FULLSCREEN) == 0) {
// TODO: The system bars are visible. Make any desired
// adjustments to your UI, such as showing the action bar or
// other navigational controls.
System.out.print("Change event");
} else {
// TODO: The system bars are NOT visible. Make any desired
// adjustments to your UI, such as hiding the action bar or
// other navigational controls.
System.out.print("Change event");
}
}
});
Do you know how I can know if the status bar has re-appeared?
In my activity I do this to get it re-hide the status bar:
@Override
public void onWindowFocusChanged(boolean hasFocus)
{
System.out.println("Gotcha");
super.onWindowFocusChanged(hasFocus);
final Handler handler = new Handler();
handler.postDelayed(new Runnable()
{
@Override
public void run() {
System.out.println("Hiding");
_root.setSystemUiVisibility(View.SYSTEM_UI_FLAG_FULLSCREEN
| View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY
| View.SYSTEM_UI_FLAG_HIDE_NAVIGATION
| View.SYSTEM_UI_FLAG_FULLSCREEN
| View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN
| View.SYSTEM_UI_FLAG_LAYOUT_STABLE);
}
}, 6000);
}