1

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.

David
  • 5,481
  • 2
  • 20
  • 33
Hunter S
  • 1,293
  • 1
  • 15
  • 26

2 Answers2

3

You need to use themes for application and activity styling as explained here: android:theme="@android:style/Theme.NoTitleBar.Fullscreen" works on Application level but not at the activity level. Any clue?. Those are the ones applied when creating the view, instead of removing them after creating in onResume, like you do.

Basically, you need to set a theme for the application that won't have a title bar/action bar (if you already have a theme, have it extend this one):

<application
    ...
    android:theme="@android:style/Theme.NoTitleBar.Fullscreen" >
</application>

Similarly for every activity:

<activity

     android:theme="@android:style/Theme.NoTitleBar.Fullscreen" >
     ...
</activity>

And in activity's onCreate:

super.onCreate(savedInstanceState);
requestWindowFeature(Window.FEATURE_NO_TITLE);
getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,WindowManager.LayoutParams.FLAG_FULLSCREEN);
Community
  • 1
  • 1
Sasa Sekulic
  • 669
  • 4
  • 12
0

I managed to solve my problem and eliminate some unnecessary code snippets that I had in my app.

Making an app full screen -- including hiding the navigation and status bar -- involved quite a few parts:



Set the app theme in the android manifest to "Theme.NoTitleBar.Fullscreen"
(Done in AndroidManifest.xml)

<application
    android:allowBackup="true"
    android:icon="@drawable/ic_launcher"
    android:label="@string/app_name"
    android:theme="@android:style/Theme.NoTitleBar.Fullscreen" >


Create global variables for the window decor view and UI options
(Done on the programming side of all activities)

private View decorView;
private int uiOptions;

NOTE: Do not define until onCreate()



Define decorView and uiOptions and call a function to create a UI change listener in onCreate()
(Done on the programming side of all activities)

@Override
protected void onCreate(Bundle savedInstanceState) {

    super.onCreate(savedInstanceState);

    setContentView(R.layout.activity_main);

    decorView = getWindow().getDecorView();

    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;

    createUiChangeListener();

}


Set the system UI visibility in onResume()
(Done on the programming side of all activities)

@Override
protected void onResume() {

    super.onResume();

    decorView.setSystemUiVisibility(uiOptions);

}


Code for the createUiChangeListener() function called from onCreate()
(Done on the programming side of all activities)

private void createUiChangeListener() {

    decorView.setOnSystemUiVisibilityChangeListener (
            new View.OnSystemUiVisibilityChangeListener() {

                @Override
                public void onSystemUiVisibilityChange(int pVisibility) {

                    if ((pVisibility & View.SYSTEM_UI_FLAG_FULLSCREEN) == 0) {
                        decorView.setSystemUiVisibility(uiOptions);
                    }

                }

            });

}
Community
  • 1
  • 1
Hunter S
  • 1,293
  • 1
  • 15
  • 26
  • This causes heap size to increase, have you noticed this? As reference please refer to my question, I used the same approach as yours http://stackoverflow.com/questions/32492441/why-does-heap-size-keep-increasing – John Ernest Guadalupe Sep 10 '15 at 03:09