Remove gap at the top of fragment when actionBar is hidden
<p>I have a problem with a gap being displayed at the top of a fragment when I do actionBar.hide() (btw I don't see this gap on the simulator, only on a real device). I tried <a href="https://stackoverflow.com/questions/28007921/overlaying-the-action-bar-not-working">this answer</a> and <a href="https://stackoverflow.com/questions/17757424/make-fragments-full-screen-programmatically">that one</a>, but nothing works. This fragment is inside MainActivity, which loads different fragments when I click on the menu. It's the only fragment where the actionBar (which is custom) should be hidden, so I cannot set the fullscreen flag on MainActivity onCreate() method. How can I redraw the view so the actionBar empty space disappear?</p>

<p>Here is how it looks now:</p>

<p><a href="https://i.stack.imgur.com/PmK3v.jpg" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/PmK3v.jpg" alt="enter image description here"></a></p>

<p>This is the mainActivty where I load the fragment:</p>

<pre><code>public void onCreate(Bundle savedInstanceState) {

        getWindow().requestFeature(Window.FEATURE_ACTION_BAR);
        getWindow().requestFeature(Window.FEATURE_ACTION_BAR_OVERLAY);
        super.onCreate(savedInstanceState);

        showActionBar();

        if(Build.VERSION.SDK_INT &gt;= 21){
            getWindow().getDecorView().setSystemUiVisibility(
                    View.SYSTEM_UI_FLAG_LAYOUT_STABLE
                            | View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN);
        }
        setContentView(R.layout.activity_main);
        setUpMenu();
}
</code></pre>

<p>On click on the menu, I change the fragment accordingly:</p>

<pre><code>@Override
    public void onClick(View view) {
        if (view == itemProfile){
            mActionBar.hide();
            ProfileFragment profile = new ProfileFragment();
            profile.setUser(AppController.getInstance().getLoggedInUser());
            changeFragment(profile);
        }
}
</code></pre>

<p>And the custom actionBar</p>

<pre><code>private void showActionBar() {
        mActionBar = getSupportActionBar();
        mActionBar.setDisplayShowHomeEnabled(false);
        mActionBar.setDisplayShowTitleEnabled(false);
        ColorDrawable colorDrawable = new ColorDrawable(Color.parseColor("#ffffff"));
        mActionBar.setBackgroundDrawable(colorDrawable);
        LayoutInflater mInflater = LayoutInflater.from(this);

        View mCustomView = mInflater.inflate(R.layout.custom_actionbar, null);
        mTitleTextView = (TextView) mCustomView.findViewById(R.id.title_text);
        mLogo = (ImageView) mCustomView.findViewById(R.id.logo);

        ImageButton menuButton = (ImageButton) mCustomView
                .findViewById(R.id.menu);
        menuButton.setOnClickListener(new View.OnClickListener() {

            @Override
            public void onClick(View view) {
                if (resideMenu.isOpened()) {
                    resideMenu.closeMenu();
                } else {
                    resideMenu.openMenu();
                }
            }
        });

        ImageButton mapButton = (ImageButton) mCustomView
                .findViewById(R.id.map);
        mapButton.setOnClickListener(new View.OnClickListener() {

            @Override
            public void onClick(View view) {
                Intent i = new Intent(getApplicationContext(), MapsActivity.class);
                startActivity(i);
            }
        });

        mActionBar.setCustomView(mCustomView);
        mActionBar.setDisplayShowCustomEnabled(true);

    }
</code></pre>

<p>My theme:</p>

<pre><code>&lt;style name="AppTheme" parent="Theme.AppCompat.Light"&gt;
    &lt;item name="android:colorPrimaryDark"&gt;@android:color/black&lt;/item&gt;
    &lt;item name="android:windowActionBarOverlay"&gt;true&lt;/item&gt;
&lt;/style&gt;
</code></pre>

<p>My mainActivity layout:</p>

<pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt;
&lt;FrameLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:fitsSystemWindows="true"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"&gt;

    &lt;FrameLayout
        android:id="@+id/main"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"&gt;

        &lt;LinearLayout
            android:orientation="vertical"
            android:layout_width="match_parent"
            android:layout_height="match_parent"&gt;

            &lt;FrameLayout
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:orientation="vertical"
                android:id="@+id/main_fragment"&gt;
            &lt;/FrameLayout&gt;

        &lt;/LinearLayout&gt;
    &lt;/FrameLayout&gt;
&lt;/FrameLayout&gt;
</code></pre>

<p>My custom actionBar</p>

<pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt;
&lt;RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:background="@color/transparent"&gt;

    &lt;FrameLayout
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:background="@color/transparent"&gt;

        &lt;TextView
        android:id="@+id/title_text"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:padding="7dp"
        android:fontFamily="sans-serif-light"
        android:text="@string/app_title"
        android:textSize="@dimen/textsize_large"
        android:textColor="@android:color/black"
        android:layout_gravity="center"
        android:visibility="gone"/&gt;

        &lt;ImageView
            android:id="@+id/logo"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:padding="7dp"
            android:layout_gravity="center"
            android:src="@drawable/logo"
            android:background="@color/transparent" /&gt;

        &lt;ImageButton android:src="@drawable/earth"
            android:background="?attr/actionBarItemBackground"
            android:layout_width="?attr/actionBarSize"
            android:layout_height="20dp"
            android:scaleType="centerInside"
            android:id="@+id/map"
            android:layout_alignParentRight="true"
            android:layout_alignParentTop="true"
            android:layout_gravity="right|center_vertical"
            android:layout_marginRight="-15dp"
            android:tint="@color/black"/&gt;

        &lt;ImageButton android:src="@drawable/titlebar_menu_selector"
            android:background="?attr/actionBarItemBackground"
            android:layout_width="?attr/actionBarSize"
            android:layout_height="match_parent"
            android:scaleType="centerInside"
            android:id="@+id/menu"
            android:layout_alignParentLeft="true"
            android:layout_alignParentTop="true"
            android:layout_marginLeft="-15dp"
            android:layout_gravity="left|center_vertical"
            android:tint="@color/black"/&gt;

    &lt;/FrameLayout&gt;

&lt;/RelativeLayout&gt;
</code></pre>

<p>Any help would be great, I've been fighting with it for days now and I really don't know what to do...</p>