I am currently writing an Android app with a completely full screen experience (the system bar and navigation bar are not displayed until the user swipes down) for a Nexus 7 tablet.
For some reason, when I switch activities, the navigation bar reappears briefly.
To create the full screen effect, I set to the system UI visibility to predetermined options in each activity's onResume()
, register a UI change listener, and register a window focus listener.
UI Options
private View decorView = getWindow().getDecorView();
private int uiOptions = View.SYSTEM_UI_FLAG_LAYOUT_STABLE
| View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION
| View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN
| View.SYSTEM_UI_FLAG_HIDE_NAVIGATION
| View.SYSTEM_UI_FLAG_FULLSCREEN
| View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY;
Setting the System UI Visibilility in onResume()
@Override
protected void onResume() {
super.onResume();
decorView.setSystemUiVisibility(uiOptions);
}
Setting the System UI Visibility When the UI Changes
decorView.setOnSystemUiVisibilityChangeListener (
new View.OnSystemUiVisibilityChangeListener() {
@Override
public void onSystemUiVisibilityChange(int pVisibility) {
if ((pVisibility & View.SYSTEM_UI_FLAG_FULLSCREEN) == 0) {
decorView.setSystemUiVisibility(uiOptions);
}
}
});
Setting the System UI Visibility When the Window Has Focus
@Override
public void onWindowFocusChanged(boolean pHasFocus) {
super.onWindowFocusChanged(pHasFocus);
if(pHasFocus) {
decorView.setSystemUiVisibility(uiOptions);
}
}
All of the things above are done in each activity of the application to ensure that the navigation bar and status bar are hidden when a keyboard goes away, an activity is resumed, etc.
But, I still have the problem of the navigation bar appearing briefly when I switch between activities.
Any help is greatly appreciated! Thank you.