1

I used the way https://stackoverflow.com/a/27051852/3875363 to achieve the drawer behind the status bar, it seems fine before only stay for one view.

But I faced a strange case after I hide and show this fragment, a white padding appears on the bottom of the drawerlayout, it likes below.

enter image description here

I comment most codes to show a simple example.

The layout of activity:

<?xml version="1.0" encoding="utf-8"?>
<FrameLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/content_layout"
    android:layout_width="match_parent"
    android:layout_height="match_parent">

</FrameLayout>

The layout of fragment with drawer

<android.support.v4.widget.DrawerLayout android:id="@+id/drawer_layout"
                                        xmlns:android="http://schemas.android.com/apk/res/android"
                                        xmlns:tools="http://schemas.android.com/tools"
                                        android:layout_width="match_parent"
                                        android:layout_height="match_parent"
                                        android:fitsSystemWindows="true"
                                        tools:context=".MainActivity">

    <RelativeLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent">

        <include
            android:id="@+id/action_bar_in_list"
            layout = "@layout/toolbar"/>

    </RelativeLayout>

    <com.ghostflying.portalwaitinglist.ScrimInsetsFrameLayout
        xmlns:android="http://schemas.android.com/apk/res/android"
        xmlns:app="http://schemas.android.com/apk/res-auto"
        android:id="@+id/debug_content"
        android:background="@color/setting_item_group_title_text"
        app:insetForeground="#4000"
        android:fitsSystemWindows="true"
        android:layout_gravity="start"
        android:layout_height="match_parent"
        android:layout_width="@dimen/navigation_drawer_width">

    </com.ghostflying.portalwaitinglist.ScrimInsetsFrameLayout>
</android.support.v4.widget.DrawerLayout>

The layout of the second fragment:

<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
             xmlns:tools="http://schemas.android.com/tools"
             android:layout_width="match_parent"
             android:layout_height="match_parent">

    <!-- TODO: Update blank fragment layout -->
    <TextView
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:text="@string/hello_blank_fragment"/>

</FrameLayout>

Once I hide the drawer fragment, show the second fragment, then I popup the back stack to return. The drawer fragment will seem like the image, a padding with the height of status bar always appear. So strange.

Community
  • 1
  • 1
GhostFlying
  • 809
  • 1
  • 7
  • 17

2 Answers2

0

Try to remove android:paddingBottom from DrawerLayout. android:paddingTop makes Drawer doesn't cover the Status Bar, but there is no reason to duplicate padding at the bottom.

EDIT: After your update, I analyzed it once more and I think your issue can be caused by your unusual design. All guides suggest that DrawerLayout should be root element of view hierarchy (as in your example you provided). See here: link

So I suggest one of these solutions.

  1. Use separate Activities to display Views with and without Drawer. (I recommend this, especially when your Drawer plays navigational role.)

  2. Use one Activity with Drawer Layout as root and put Fragments as Drawer's main content. If you don't want Drawer to be openable use this method after changing Fragment: mDrawerLayout.setDrawerLockMode(DrawerLayout.LOCK_MODE_LOCKED_CLOSED);

paulina_glab
  • 2,467
  • 2
  • 16
  • 25
  • In fact, the padding is all 0dp, I comment most codes, it seems also very strange, I'll edit the question later. – GhostFlying Dec 22 '14 at 11:09
0

Try to remove the android attribute:

fitsSystemWindows = "true"

This worked for me.

According to the official documentation it's a

Boolean internal attribute to adjust view layout based on system windows such as the status bar. If true, adjusts the padding of this view to leave space for the system windows.

Draken
  • 3,134
  • 13
  • 34
  • 54