Search code examples
androidandroid-layoutandroid-window

Disable fullscreen mode after setting FLAG_LAYOUT_IN_SCREEN in Android


I have to inherit a custom main activity class which is a 3rd party lib and I cannot make any change to the class. This class adds FLAG_LAYOUT_IN_SCREEN to the window and it causes the app to be on full screen. However, I wanna prevent this behavior. So, the question is how can I clear/disable the full screen mode and can display navigation bar/status bar?

Here is the custom main activity class

public class CustomActivity extends Activity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
       super.onCreate(savedInstanceState);
       this.getWindow().addFlags(WindowManager.LayoutParams.FLAG_LAYOUT_IN_SCREEN);
       setContentView(new FrameLayout(this));
       // rest...
    }
}

Here is my activity class:

public class MyActivity extends CustomActivity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
       super.onCreate(savedInstanceState);
       // tried these attempts below, but none of them prevented 
       // the fullscreen mode which hides navigation bar and status bar.
       this.getWindow().clearFlags(WindowManager.LayoutParams.FLAG_LAYOUT_IN_SCREEN);
       this.getWindow().addFlags(WindowManager.LayoutParams.FLAG_FORCE_NOT_FULLSCREEN);
       this.getWindow().addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);
    }
}

Note: You can also test it on a sample app easily. You would notice once you add the FLAG_LAYOUT_IN_SCREEN, full-screen mode remains for different attempts as well.

public class MainActivity extends Activity {
    private FrameLayout mainLayout;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        this.getWindow().addFlags(FLAG_LAYOUT_IN_SCREEN);
        setContentView(new FrameLayout(this));
        this.getWindow().clearFlags(FLAG_LAYOUT_IN_SCREEN);
        this.getWindow().addFlags(FLAG_KEEP_SCREEN_ON);
    }

Solution

  • Please apply the following to the app to not be as full screen (showing status bar)

    getWindow().getDecorView().setSystemUiVisibility(View.SYSTEM_UI_FLAG_LAYOUT_STABLE);       
    getWindow().clearFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN);