Why does my layout get messed up after clearing FLAG_TRANSLUCENT_STATUS flag?

android window flags
flag_layout_no_limits
flag_not_touchable
flag_show_when_locked
flag_dismiss_keyguard
layout_in_display_cutout_mode_short_edges
soft_input_adjust_nothing
type_keyguard_dialog

I have a single Activity application. It displays a LoginFragment which makes Status and Navigation bars translucent so that it can display a background image behind it. However, after login this fragment is replaced by another fragment which needs to display the usual solid Status and Navigation bars. So, before LoginFragment gets removed it unsets the flags it had set, to make the bars opaque.

The problem that I am facing is that after I login, the fragment with normal Status and Navigation bars has its Action bar displaced down. If I rotate my screen to landscape and then back to portrait to force the recreation of the layout then the Action bar snaps back to correct position.

When Status bar is translucent. This is perfectly fine.

On next screen Action bar is displaced downwards. Also notice that Status bar is black in color, it should have been gray, according to theme.

Now if I go back to first screen, the top translucent bar is fine, but the whole content is shifted upwards, leaving a blank white space below.

Code in LoginFragment which programmatically makes the bars translucent and also restores them:-

@Override
public void onResume() {
    super.onResume();
    if (hasTransparentStatusBar()) {
        setStatusBarTranslucent();
    }
}

@Override
public void onPause() {
    if (hasTransparentStatusBar()) {
        setStatusBarOpaque();
    }
    super.onPause();
}

protected boolean hasTransparentStatusBar() {
    return true;
}

protected void setStatusBarTranslucent() {
    if (Build.VERSION.SDK_INT >= 21) {
        Window window = getActivity().getWindow();
        window.addFlags(WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS
                | WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS
                | WindowManager.LayoutParams.FLAG_TRANSLUCENT_NAVIGATION);
    }
}

protected void setStatusBarOpaque() {
    if (Build.VERSION.SDK_INT >= 21) {
        Window window = getActivity().getWindow();
        window.clearFlags(WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS
                | WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS
                | WindowManager.LayoutParams.FLAG_TRANSLUCENT_NAVIGATION);
    }
}

Layout xml of Activity:-

<?xml version="1.0" encoding="utf-8"?>
<android.support.v4.widget.DrawerLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:id="@+id/drawer_layout"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context="com.app.MainActivity" >

    <!-- The main content view -->

    <FrameLayout
        android:id="@+id/container"
        android:layout_width="match_parent"
        android:layout_height="match_parent" />
    <!-- The navigation drawer -->

    <ListView
        android:id="@+id/left_drawer"
        android:layout_width="240dp"
        android:layout_height="match_parent"
        android:layout_gravity="start"
        android:choiceMode="singleChoice"
        android:divider="@color/divider"
        android:dividerHeight="0dp"
        android:background="@color/primary"
        />

</android.support.v4.widget.DrawerLayout>

LoginFragment's layout xml:-

<ImageView
    android:layout_width="wrap_content"
    android:layout_height="200dp"
    android:src="@drawable/logo"
    android:id="@+id/logo"
    android:layout_centerVertical="true"
    android:layout_centerHorizontal="true" />

<Button
    android:padding="@dimen/default_margin"
    android:text="Login using Facebook"
    android:textColor="@android:color/white"
    android:background="@drawable/com_facebook_button_background"
    android:id="@+id/authButton"
    android:layout_below="@+id/logo"
    android:layout_centerHorizontal="true"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content" />

I had the same problem before, so if anybody stumbles on this, the correct workaround is to set the NO_LIMITS flag :

if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
    Window window = getWindow();
    window.addFlags(WindowManager.LayoutParams.FLAG_LAYOUT_NO_LIMITS);
}

Bottom Navigation Bar gets messed up after clearing flag translucent , Use grok to add the log filename as a field in logstash � regex logstash GPIO Pin 17 does not trigger RPi.GPIO callback Why does my layout get messed up after clearing FLAG_TRANSLUCENT_STATUS flag? stackoverflow.com� Teams Private questions and answers for your team; android-layout. Score 3. Posts 2. android-fragments 1 Why does my layout get messed up after clearing FLAG

I had similar problem and it seems we should set window flags before onActivityCreated(Bundle). I'm often using static methods to showing my fragments, like this:

public class FragmentPlayer extends MediaFragment
{

    public FragmentPlayer()
    {
        // Default public constructor required. 
    }

    public static void show(@NonNull Activity activity, boolean compact)
    {
        boolean isOrientationPortrait = UiHelper.isOrientationPortrait(activity);
        setupWindow(activity.getWindow(), isOrientationPortrait, compact);

        FragmentManager fragmentManager = activity.getFragmentManager();
        FragmentTransaction transaction = fragmentManager.beginTransaction();
        FragmentPlayer newFragment = FragmentPlayer.getInstance(compact);
        transaction.replace(R.id.fragment_player, newFragment);
        transaction.commit();
    }

    private static void setupWindow(@NonNull Window window, final boolean isOrientationPortrait,
                                    final boolean compact)
    {
        if (compact)
        {
            window.addFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS);
            window.clearFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_NAVIGATION);
        }
        else
        {
            if (isOrientationPortrait)
            {
                window.addFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS);
                window.addFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_NAVIGATION);
            }
            else
            {
                window.clearFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS);
                window.clearFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_NAVIGATION);
            }
        }
    }   
}

As you can see I moved all Window initialization from onCreateActivity(Bundle) to static method setupWindow(Window, boolean, boolean) and now everything works just fine.

Still don't know why layout actually get's messed up when calling those methods from onCreateActivity(Bundle), but that's the start.

Edit 1: oh, and don't forget to also setup your Window in Activity.onCreate(Bundle) to properly handle screen rotations!

User tchap, android.animation.LayoutTransition; In that case we receive a call back from {@link ActivityThread} and this flag is used to The decor view visibility will get adjusted when the app get Surface can never be reassigned or cleared (use Surface.clear()). the test below should not fail unless someone is messing with us. Content you paste into your campaigns from an outside source, like a website or word processor, can apply extra HTML code that alters your campaign layout or restricts your ability to make changes. The Clear Styles button in Mailchimp's editor toolbar helps remove extra style code from your content after it's pasted into your campaign.

After setting all those flags on the window for the transparent status bar. Calling w.getDecorView().requestApplyInsets() fixes the issue. Credits to @Froyo in the comments

core/java/android/view/ViewRootImpl.java, This list will be cleared after the transitions on the list are start()'ed. These. * transitionsa re LayoutParams.FLAG_TRANSLUCENT_STATUS) != 0) { If we' re checking the layout flags, then we need to clean them up also. for (int i = 0; the test below should not fail unless someone is messing with us. checkThread();. Thus, if you remove the "boot flag" on an ESP, it will likely pop up with an "msftdata flag," since ESPs use FAT, and FAT partitions get the "msftdata flag" by default. (In older versions of libparted, the "msftdata flag" doesn't exist, so the partition would have no flag.)

I tried all possibilities to fix this issue and found a clear solution. First do the things shown in the youtube video and add android:fitsSystemWindows="true" to android.support.v7.widget.Toolbar in xml.

sdk/sources/android-19/android/view/ViewRootImpl.java, mClientWindowLayoutFlags = attrs.flags; setAccessibilityFocus(null, null); if (view instanceof This list will be cleared after the transitions on the list are start()'ed. FLAG_TRANSLUCENT_STATUS) != child) { // the test below should not fail unless someone is messing with us checkThread(); if (mView == child) { mView. To enable immersive mode, call setSystemUiVisibility() and pass the SYSTEM_UI_FLAG_IMMERSIVE flag in conjunction with SYSTEM_UI_FLAG_FULLSCREEN and SYSTEM_UI_FLAG_HIDE_NAVIGATION. If your app has its own controls that aren't needed when a user is immersed in content, make them disappear and reappear in sync with the system bars.

ViewRootImpl.java - Android社区, The decor view visibility will get adjusted when the app get // stopped and that's when Surface can never be reassigned or cleared (use Surface.clear()). final the first layout -before- adding to the window // manager, to make sure we do the test below should not fail unless someone is messing with us� (and my graphics card drivers have nothing to do with keyboard input) Example: if I load up GTA 5, then hit Start-D to switch back to Windows to do stuff, when I switch back to GTA and hit "R" on the keyboard, it flips back to windows and opens up the bottom-left Start menu. Other keys do other things like that.

core/java/android/view/ViewRootImpl.java, softInputMode; // Keep track of the actual window flags supplied by the client. This list will be cleared after the transitions on the list are start()'ed. The setup * happens during the layout phase of traversal, which we want to child) { // the test below should not fail unless someone is messing with us� Open up google.com, or another site that has a prominent heading or other block-level element. Right/Cmd + click on the element in question and choose Inspect/Inspect element (or whatever the option is in your browser) — this should open up the dev tools in your browser, with the element highlighted in the DOM inspector.

core/java/android/view/ViewRootImpl.java , 10444d1f4f1aSHall Liu * This list will be cleared after the transitions on the list are start()'ed. FLAG_TRANSLUCENT_STATUS) != without checking/clearing the 22044d1f4f1aSHall Liu // layout flags, since requests happening 2295 4d1f4f1aSHall Liu // the test below should not fail unless someone is messing with us� A: Well I cant find any (WORKING) language pack for this if you find one you can just drag and drop the TTF/file in the in the font file in control panel (MOST OF THE TIME) some times its a lot harder for XP users you put the ZIPPED file in a new folder in C:(Folder Name Here) and extract the files in the folder keep the zip file and go in your

Comments
  • Finally the only workaround which fixed this is that I moved LoginFragment under another new Activity which displays its fragments in immersive mode. The rest fragments are still served by the original Activity.
  • I had a similar problem but with views instead of fragments. For me, w.getDecorView().requestApplyInsets() worked after clearing translucent flag.
  • This should be the accepted answer from Froyo, I am going to post it!
  • I have absolutely no idea why, but I confirm that this works (setting FLAG_LAYOUT_NO_LIMITS instead of FLAG_TRANSLUCENT_STATUS makes the status bar translucent and it doesn't leave blank space at the bottom).
  • This causes problems with the navigation bar on devices that have UI navigation bars instead of hardware buttons (e.g. Nexus 5X)