Switching from full screen to not full screen pop/slide
Asked Answered
E

8

7

Going from not full screen to full screen with Android works fine. However, upon returning from my full screen activity (a full screen video player), the activity pops in sliding down as the status bar animates down. It seems that the resuming activity is animated in from the full screen mode but with the status bar not there the actual activity is being painted as if it were missing.

I have tried messing with my manifest file specifying themes/styles. I have tried doing this programmatically in onCreate() before the content view is set and various other places in the activity life cycle:

getWindow().addFlags(WindowManager.LayoutParams.FLAG_FORCE_NOT_FULLSCREEN);
getWindow().clearFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN);

It seems that there is no way to keep the status bar from animating down and/or from the content view from first drawing without the status bar there and then adjusting down as it is re-shown.

Anyone have any thoughts on this? I am not sure if there is any way to change this and is just a behavior of Android.

Thanks in advance.

Erida answered 6/10, 2011 at 0:51 Comment(2)
how did you resolve your issue? Can you please explain or give some reference?Ally
I used the accepted answer below by Robert Nekic.Erida
F
2

You need a few more flags: FLAG_LAYOUT_IN_SCREEN and FLAG_LAYOUT_NO_LIMITS.

Check out http://nubinewsblog.blogspot.com/2009/11/smooth-full-screen-transition.html.

Farra answered 8/11, 2011 at 17:5 Comment(1)
It's unfortunate the solution requires paddingTop but it works. Thank you.Erida
C
2
private void toggleFullscreen(boolean fullscreen)
{
    WindowManager.LayoutParams attrs = getWindow().getAttributes();
    if (fullscreen)
    {
        attrs.flags |= WindowManager.LayoutParams.FLAG_FULLSCREEN;
    }
    else
    {
        attrs.flags &= ~WindowManager.LayoutParams.FLAG_FULLSCREEN;
    }
    getWindow().setAttributes(attrs);
}

Use this it will surely work

Coast answered 21/8, 2014 at 6:13 Comment(0)
G
2

Following is my solution:

Show the system state bar before finish the full screen Activity

@Override
public void onBackPressed() {
  getWindow().setFlags(WindowManager.LayoutParams.FLAG_FORCE_NOT_FULLSCREEN, WindowManager.LayoutParams.FLAG_FORCE_NOT_FULLSCREEN);

    mUIHandler.post(new Runnable() {
        @Override
        public void run() {
            MyFullScreenActivity.super.onBackPressed();
        }
    });
}
Gerdy answered 25/11, 2016 at 3:49 Comment(1)
this solution was more useful to me because it didn't cause the original activity to have to adjust its layout padding.Stephanystephen
W
2

I've finally found the perfect way to handle this case, without messing with padding.

You just have to call this line, in the activity which is non-fullscreen :

getWindow().getDecorView().setSystemUiVisibility(View.SYSTEM_UI_FLAG_LAYOUT_STABLE);

This way the layout won't be changed when presenting a fullscreen activity, and you won't see the status bar pop.

Welldefined answered 9/9, 2018 at 18:9 Comment(1)
Together with fitsSystemWindows, this solves my problem perfectlyFriedland
T
1

In the root view of the activity layout add

android:paddingTop="25dp"

In the onCreate of the activity, before the setContentView() add

 getWindow().addFlags(WindowManager.LayoutParams.FLAG_LAYOUT_IN_SCREEN);
 getWindow().addFlags(WindowManager.LayoutParams.FLAG_LAYOUT_NO_LIMITS);
Trafalgar answered 7/7, 2014 at 8:35 Comment(0)
C
1

Here is the perfect way to eliminate this problem:

private void setFullscreen(boolean fullscreen) {
    WindowManager.LayoutParams attrs = getWindow().getAttributes();
    if (fullscreen) {
        attrs.flags |= WindowManager.LayoutParams.FLAG_FULLSCREEN;
        attrs.flags |= WindowManager.LayoutParams.FLAG_LAYOUT_IN_SCREEN;
        attrs.flags |= WindowManager.LayoutParams.FLAG_LAYOUT_NO_LIMITS;
    }
    else {
        attrs.flags &= ~WindowManager.LayoutParams.FLAG_FULLSCREEN;
        attrs.flags &= ~WindowManager.LayoutParams.FLAG_LAYOUT_IN_SCREEN;
        attrs.flags &= ~WindowManager.LayoutParams.FLAG_LAYOUT_NO_LIMITS;
    }
    getWindow().setAttributes(attrs);
}

Call this before super.onCreate(...) inside your Activity.

Chronic answered 16/8, 2017 at 6:51 Comment(0)
L
0

I was able to achieve this in two steps.

  1. Use Theme.AppCompat.Light.NoActionBar in my styles for the Activity which I want to show as fullscreen.

  2. Use the below code in the Activity's onCreate(Bundle savedInstanceState) method WindowManager.LayoutParams attributes = getWindow().getAttributes(); attributes.flags |= WindowManager.LayoutParams.FLAG_LAYOUT_IN_SCREEN | WindowManager.LayoutParams.FLAG_LAYOUT_NO_LIMITS; getWindow().setAttributes(attributes);

Hope this helps. Happy Coding :)

Lavolta answered 14/11, 2016 at 14:58 Comment(0)
W
0

I don't know if this will work for you but it worked for me. Set full screen activity:

getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,WindowManager.LayoutParams.FLAG_FULLSCREEN);
setContentView(R.layout.my_screen);

turn off full screen:

WindowManager.LayoutParams attrs = getWindow().getAttributes();
attrs.flags |= WindowManager.LayoutParams.FLAG_LAYOUT_IN_SCREEN | WindowManager.LayoutParams.FLAG_LAYOUT_NO_LIMITS;
getWindow().clearFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN);
getWindow().setAttributes(attrs);
startActivity(new Intent(getBaseContext(),NewActivity.class));
finish();
Waxman answered 26/3, 2017 at 1:11 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.