状态栏下方的导航抽屉

时间:2015-08-29 07:28:04

标签: java android xml

我正在使用设计支持库制作导航抽屉。在我的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>

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

2 个答案:

答案 0 :(得分: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);
    }
}

答案 1 :(得分:0)

只需添加android:fitsSystemWindows =&#34; false&#34;到DrawerLayout将解决问题

相关问题