状态栏下方的导航抽屉

6
我正在尝试使用Design支持库制作导航抽屉。在我的activity_main中,我编写了以下代码。
<?xml version="1.0" encoding="utf-8"?>

    <android.support.v4.widget.DrawerLayout
        xmlns:android="http://schemas.android.com/apk/res/android"
        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">

    <LinearLayout
        android:id="@+id/layout"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:orientation="vertical">

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

    <FrameLayout 
        android:id="@+id/container"
        android:layout_width="match_parent"
        android:layout_height="match_parent"/>   

    </LinearLayout>

   <android.support.design.widget.NavigationView
        android:id="@+id/navigation_view"
        android:layout_width="wrap_content"
        android:layout_height="match_parent"
        android:layout_gravity="start"
        app:headerLayout="@layout/header_layout"
        app:menu="@menu/menu_drawer"/>  

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

当我运行我的应用程序时,它可以工作并显示导航抽屉,但它在状态栏下方而不是上方。我该如何将其移动到状态栏上方?

将抽屉布局的高度设置为“fill_parent”。 - pRaNaY
@pRaNaY,fill_parent已被弃用,现已被match_parent所取代。 - Ludovico Parsi
link - pRaNaY
3个回答

14

只需将android:fitsSystemWindows="false"添加到DrawerLayout中即可解决该问题。


0

在导航视图的 XML 中使用此代码:

app:insetForeground="#ffffff"

0

将您的活动设为全屏以克服状态栏,或使用WWW上可用的任何其他方法,但在状态栏上方放置抽屉不是一个好的选择。

public class ActivityName extends Activity {
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        // remove title
        requestWindowFeature(Window.FEATURE_NO_TITLE);
        getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
            WindowManager.LayoutParams.FLAG_FULLSCREEN);
        setContentView(R.layout.main);
    }
}

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接