0
votes

I have an App containing a toggle FullScreen function.
It did success to toggle fullscreen using the following code.

    if (tofull) {

        if (Build.VERSION.SDK_INT < 16) {
            Log.i("toggleFullScreen", "API<16");
            getWindow().setFlags(
                    WindowManager.LayoutParams.FLAG_FULLSCREEN,
                    WindowManager.LayoutParams.FLAG_FULLSCREEN);
        } else {
            Log.i("toggleFullScreen", "API>=16");
            View decorView = getWindow().getDecorView();
            // Hide the status bar.
            // int uiOptions = View.SYSTEM_UI_FLAG_FULLSCREEN;
            int uiOptions = View.SYSTEM_UI_FLAG_FULLSCREEN
                    | View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY;
            decorView.setSystemUiVisibility(uiOptions);
        }

    } else {
        if (Build.VERSION.SDK_INT < 16) {
            Log.i("toggleFullScreen", "API<16");
            getWindow().clearFlags(
                    WindowManager.LayoutParams.FLAG_FULLSCREEN);
        } else {
            Log.i("toggleFullScreen", "API>=16");
            View decorView = getWindow().getDecorView();
            // Hide the status bar.
            int uiOptions = View.SYSTEM_UI_FLAG_VISIBLE;
            decorView.setSystemUiVisibility(uiOptions);
        }
    }

It can hide status bar after toggled to fullscreen mode.

However, when I pressed hardware menu key button (I have an options menu which will show up after menu key pressed), the status bar comes out. And status bar does not hide again.

What will be the possible reason for this problem exists?
Could anyone solve it(make the status bar hide again automatically)?

2

2 Answers

0
votes

That because the flags are been cleared and you need to call your full screen function again.

please read this article . https://developer.android.com/training/system-ui/immersive.html

Note that this only from api 19.

0
votes

Please override this method on your activity

@Override
public boolean onKeyUp(int keyCode, KeyEvent event) {

    if (keyCode == KeyEvent.KEYCODE_MENU) {
        Log.d(TAG,"did pressed menu button");
        return true;
    }
    return super.onKeyUp(keyCode, event);
}

so this way you can avoid menu is shown when you app is on full-screen mode.