删除 api 版本 > 21 中出现的 DrawerLayout 顶部填充

Remove DrawerLayout top padding that appear in api version > 21

所以,基本上我是用自定义菜单实现 drawerLayout(我使用的是 recyclerView 而不是 navigationView)。如果我 运行 应用程序的最新版本 android (> lollipop),则会出现顶部填充。无论如何要删除顶部填充?我尝试在 drawerLayout 上设置 fitSystemWindows=true 但无济于事。

代码

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

        <include
            layout="@layout/app_bar_store_landing"
            android:layout_width="match_parent"
            android:layout_height="match_parent" />

        <android.support.v4.widget.NestedScrollView
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:layout_gravity="start"
            android:fitsSystemWindows="true">
            <LinearLayout
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:orientation="vertical">

                <RelativeLayout
                    android:layout_width="match_parent"
                    android:layout_height="50dp"
                    android:background="@color/drawer_bg"
                    android:paddingLeft="20dp">
                    <ImageView
                        android:id="@+id/menuIcon"
                        android:layout_width="35dp"
                        android:layout_height="35dp"
                        android:layout_centerVertical="true"
                        android:src="@drawable/location_menu"
                        android:layout_marginRight="10dp"/>

                    <LinearLayout
                        android:layout_width="match_parent"
                        android:layout_height="wrap_content"
                        android:orientation="vertical"
                        android:layout_centerVertical="true"
                        android:layout_toRightOf="@+id/menuIcon">
                        <TextView
                            android:layout_width="match_parent"
                            android:layout_height="wrap_content"
                            android:text="Jalan Tunku Ismail"
                            android:textColor="@android:color/white"
                            android:ellipsize="end"
                            android:singleLine="true"
                            android:textStyle="bold"/>
                        <TextView
                            android:layout_width="match_parent"
                            android:layout_height="wrap_content"
                            android:text="Tap to change location"
                            android:textColor="@color/grey_text" />
                    </LinearLayout>
                </RelativeLayout>


                <RelativeLayout
                    android:layout_width="match_parent"
                    android:layout_height="50dp"
                    android:background="@color/drawer_bg"
                    android:paddingLeft="20dp">
                    <ImageView
                        android:id="@+id/menuIcon2"
                        android:layout_width="35dp"
                        android:layout_height="35dp"
                        android:layout_centerVertical="true"
                        android:src="@drawable/store_menu"
                        android:layout_marginRight="10dp"/>
                    <LinearLayout
                        android:layout_width="match_parent"
                        android:layout_height="wrap_content"
                        android:orientation="vertical"
                        android:layout_centerVertical="true"
                        android:layout_toRightOf="@+id/menuIcon2">
                        <TextView
                            android:layout_width="match_parent"
                            android:layout_height="wrap_content"
                            android:text="Jaya Grocer, Kuala Lumpur"
                            android:textColor="@android:color/white"
                            android:ellipsize="end"
                            android:singleLine="true"
                            android:textStyle="bold"/>
                        <TextView
                            android:layout_width="match_parent"
                            android:layout_height="wrap_content"
                            android:text="Tap to change store"
                            android:textColor="@color/grey_text" />
                    </LinearLayout>
                </RelativeLayout>

                <RelativeLayout
                    android:layout_width="match_parent"
                    android:layout_height="50dp"
                    android:background="@color/drawer_bg"
                    android:paddingLeft="20dp">
                    <ImageView
                        android:id="@+id/menuIcon3"
                        android:layout_width="35dp"
                        android:layout_height="35dp"
                        android:src="@drawable/my_account"
                        android:layout_centerVertical="true"
                        android:layout_marginRight="10dp"/>
                    <LinearLayout
                        android:layout_width="match_parent"
                        android:layout_height="wrap_content"
                        android:orientation="vertical"
                        android:layout_centerVertical="true"
                        android:layout_toRightOf="@+id/menuIcon3">
                        <TextView
                            android:layout_width="match_parent"
                            android:layout_height="wrap_content"
                            android:text="My Account"
                            android:textColor="@android:color/white"
                            android:ellipsize="end"
                            android:singleLine="true"
                            android:textStyle="bold"/>
                    </LinearLayout>
                </RelativeLayout>

                <RelativeLayout
                    android:layout_width="match_parent"
                    android:layout_height="50dp"
                    android:background="@color/drawer_bg"
                    android:paddingLeft="20dp">
                    <ImageView
                        android:id="@+id/menuIcon4"
                        android:layout_width="35dp"
                        android:layout_height="35dp"
                        android:layout_centerVertical="true"
                        android:src="@drawable/my_shopping_list"
                        android:layout_marginRight="10dp"/>
                    <LinearLayout
                        android:layout_width="match_parent"
                        android:layout_height="wrap_content"
                        android:orientation="vertical"
                        android:layout_centerVertical="true"
                        android:layout_toRightOf="@+id/menuIcon4">
                        <TextView
                            android:layout_width="match_parent"
                            android:layout_height="wrap_content"
                            android:text="My Shopping List"
                            android:textColor="@android:color/white"
                            android:ellipsize="end"
                            android:singleLine="true"
                            android:textStyle="bold"/>
                    </LinearLayout>
                </RelativeLayout>

                <View
                    android:layout_width="match_parent"
                    android:layout_height="1dp"
                    android:background="@color/grey_text" />

                <android.support.v7.widget.RecyclerView
                    android:id="@+id/menuList"
                    android:layout_width="match_parent"
                    android:layout_height="match_parent"/>
            </LinearLayout>
        </android.support.v4.widget.NestedScrollView>
    </android.support.v4.widget.DrawerLayout>

截图:

左 - Lolliop,右 - Kitkat

已修复!

在 NestedScrollView 中删除 android:fitsSystemWindows="true" 解决了问题。

好的,找到bug了。罪魁祸首是 NestedScrollView 中的 android:fitsSystemWindows="true"。删除这一行,它解决了我的问题。我想知道为什么它不影响旧版本的 android (< Kitkat)。