Android 如何将导航抽屉标题放置在状态栏下方?

Android 如何将导航抽屉标题放置在状态栏下方?,android,Android,我希望导航抽屉的标题位于状态栏下方。在搜索解决方案时,每个结果都与如何将其置于状态栏下有关。我当然尝试过“反转”这些解决方案,将标题放在下面。但它不起作用,我正在三星Galaxy S7 API 23上测试它 现在看起来是这样的: 这是我的布局,包含抽屉布局、导航视图: <?xml version="1.0" encoding="utf-8"?> <android.support.v4.widget.DrawerLayout xmlns:android="http://sche

我希望导航抽屉的标题位于状态栏下方。在搜索解决方案时,每个结果都与如何将其置于状态栏下有关。我当然尝试过“反转”这些解决方案,将标题放在下面。但它不起作用,我正在三星Galaxy S7 API 23上测试它

现在看起来是这样的:

这是我的布局,包含抽屉布局、导航视图:

<?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:background="#00ffff"
android:fitsSystemWindows="true"
tools:openDrawer="start">


  <include
    android:id="@+id/toolbar_drawer_layout"
    layout="@layout/navdrawer_toolbar"
    android:layout_width="match_parent"
    android:layout_height="match_parent" />

 <android.support.design.widget.NavigationView
    android:id="@+id/nav_view"
    android:layout_width="wrap_content"
    android:layout_height="match_parent"
    android:layout_gravity="start"
    android:background="@color/arion_darkgray"
    android:fitsSystemWindows="true"
    app:headerLayout="@layout/navdrawer_header"
    app:itemBackground="@drawable/nav_drawer_selector"
    app:itemIconTint="#fff"
    app:itemTextColor="#fff"
    app:menu="@menu/navdrawer_menu"
    app:theme="@style/custom_navDrawer_style" />

 </android.support.v4.widget.DrawerLayout>
<?xml version="1.0" encoding="utf-8"?>
<android.support.design.widget.CoordinatorLayout 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:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true"
tools:context=".MyHorseActivity">

<android.support.design.widget.AppBarLayout
    android:layout_width="match_parent"
    android:layout_height="wrap_content">

    <android.support.v7.widget.Toolbar
        android:id="@+id/myhorse_toolbar"
        android:layout_width="match_parent"
        android:layout_height="?attr/actionBarSize"
        android:background="@color/arion_darkblue">

        <RelativeLayout
            android:id="@+id/myhorse_toolbar_innerlayout"
            android:layout_width="match_parent"
            android:layout_height="?attr/actionBarSize"
            android:background="@android:color/transparent">

            <TextView
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_centerInParent="true"
                android:paddingRight="70dp"
                android:text="My Horse"
                android:textColor="#fff"
                android:textSize="24sp" />

            <ImageView
                android:backgroundTint="#ff0000"
                android:layout_width="15dp"
                android:layout_height="15dp"
                android:layout_alignParentRight="true"
                android:layout_centerInParent="true"
                android:layout_marginRight="10dp"
                android:background="@drawable/circle_shape" />
        </RelativeLayout>

    </android.support.v7.widget.Toolbar>

    <include
        layout="@layout/divider_lightblue"
        android:layout_width="match_parent"
        android:layout_height="1dp"
        android:layout_alignParentBottom="true">

    </include>


</android.support.design.widget.AppBarLayout>

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

工具栏布局:

<?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:background="#00ffff"
android:fitsSystemWindows="true"
tools:openDrawer="start">


  <include
    android:id="@+id/toolbar_drawer_layout"
    layout="@layout/navdrawer_toolbar"
    android:layout_width="match_parent"
    android:layout_height="match_parent" />

 <android.support.design.widget.NavigationView
    android:id="@+id/nav_view"
    android:layout_width="wrap_content"
    android:layout_height="match_parent"
    android:layout_gravity="start"
    android:background="@color/arion_darkgray"
    android:fitsSystemWindows="true"
    app:headerLayout="@layout/navdrawer_header"
    app:itemBackground="@drawable/nav_drawer_selector"
    app:itemIconTint="#fff"
    app:itemTextColor="#fff"
    app:menu="@menu/navdrawer_menu"
    app:theme="@style/custom_navDrawer_style" />

 </android.support.v4.widget.DrawerLayout>
<?xml version="1.0" encoding="utf-8"?>
<android.support.design.widget.CoordinatorLayout 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:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true"
tools:context=".MyHorseActivity">

<android.support.design.widget.AppBarLayout
    android:layout_width="match_parent"
    android:layout_height="wrap_content">

    <android.support.v7.widget.Toolbar
        android:id="@+id/myhorse_toolbar"
        android:layout_width="match_parent"
        android:layout_height="?attr/actionBarSize"
        android:background="@color/arion_darkblue">

        <RelativeLayout
            android:id="@+id/myhorse_toolbar_innerlayout"
            android:layout_width="match_parent"
            android:layout_height="?attr/actionBarSize"
            android:background="@android:color/transparent">

            <TextView
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_centerInParent="true"
                android:paddingRight="70dp"
                android:text="My Horse"
                android:textColor="#fff"
                android:textSize="24sp" />

            <ImageView
                android:backgroundTint="#ff0000"
                android:layout_width="15dp"
                android:layout_height="15dp"
                android:layout_alignParentRight="true"
                android:layout_centerInParent="true"
                android:layout_marginRight="10dp"
                android:background="@drawable/circle_shape" />
        </RelativeLayout>

    </android.support.v7.widget.Toolbar>

    <include
        layout="@layout/divider_lightblue"
        android:layout_width="match_parent"
        android:layout_height="1dp"
        android:layout_alignParentBottom="true">

    </include>


</android.support.design.widget.AppBarLayout>

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


在我从向导创建了NavigationDrawer类后,Android Studio自动生成了很多这类内容。你还没有把
xml
完全放好,所以我不知道你的
xml
有什么问题,但是如果你想把
导航抽屉
放在
操作栏
下面,那么就把
抽屉布局
放在你的下方
工具栏
如下

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical">

    <!--Start of the Toolbar and its items -->
    <android.support.v7.widget.Toolbar
        android:id="@+id/toolbar"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:gravity="center" />

    <android.support.v4.widget.DrawerLayout
        android:id="@+id/drawer_layout"
        android:layout_width="match_parent"
        android:layout_height="match_parent">

        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="match_parent"></LinearLayout>

        <!--Used for displaying Navigation Drawer slide-->
        <LinearLayout
            android:id="@+id/navigation_drawer"
            android:layout_width="wrap_content"
            android:layout_height="match_parent"
            android:layout_gravity="start"
            android:orientation="vertical">

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

        </LinearLayout>

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

根据您编辑的问题,抽屉布局xml将类似于

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical">

    <include
        android:id="@+id/toolbar_drawer_layout"
        layout="@layout/navdrawer_toolbar"
        android:layout_width="match_parent"
        android:layout_height="match_parent" />

    <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:background="#00ffff"
        android:fitsSystemWindows="true"
        tools:openDrawer="start">

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

        <android.support.design.widget.NavigationView
            android:id="@+id/nav_view"
            android:layout_width="wrap_content"
            android:layout_height="match_parent"
            android:layout_gravity="start"
            android:background="@color/arion_darkgray"
            android:fitsSystemWindows="true"
            app:headerLayout="@layout/navdrawer_header"
            app:itemBackground="@drawable/nav_drawer_selector"
            app:itemIconTint="#fff"
            app:itemTextColor="#fff"
            app:menu="@menu/navdrawer_menu"
            app:theme="@style/custom_navDrawer_style" />

    </android.support.v4.widget.DrawerLayout>
</LinearLayout>
<?xml version="1.0" encoding="utf-8"?>
<android.support.design.widget.CoordinatorLayout 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=".MyHorseActivity">

    <android.support.design.widget.AppBarLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content">

        <android.support.v7.widget.Toolbar
            android:id="@+id/myhorse_toolbar"
            android:layout_width="match_parent"
            android:layout_height="?attr/actionBarSize"
            android:background="@color/arion_darkblue">

            <RelativeLayout
                android:id="@+id/myhorse_toolbar_innerlayout"
                android:layout_width="match_parent"
                android:layout_height="?attr/actionBarSize"
                android:background="@android:color/transparent">

                <TextView
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_centerInParent="true"
                    android:paddingRight="70dp"
                    android:text="My Horse"
                    android:textColor="#fff"
                    android:textSize="24sp" />

                <ImageView
                    android:layout_width="15dp"
                    android:layout_height="15dp"
                    android:layout_alignParentRight="true"
                    android:layout_centerInParent="true"
                    android:layout_marginRight="10dp"
                    android:background="@drawable/circle_shape"
                    android:backgroundTint="#ff0000" />
            </RelativeLayout>

        </android.support.v7.widget.Toolbar>

        <include
            layout="@layout/divider_lightblue"
            android:layout_width="match_parent"
            android:layout_height="1dp"
            android:layout_alignParentBottom="true" />
    </android.support.design.widget.AppBarLayout>
</android.support.design.widget.CoordinatorLayout>

和工具栏布局将类似

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical">

    <include
        android:id="@+id/toolbar_drawer_layout"
        layout="@layout/navdrawer_toolbar"
        android:layout_width="match_parent"
        android:layout_height="match_parent" />

    <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:background="#00ffff"
        android:fitsSystemWindows="true"
        tools:openDrawer="start">

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

        <android.support.design.widget.NavigationView
            android:id="@+id/nav_view"
            android:layout_width="wrap_content"
            android:layout_height="match_parent"
            android:layout_gravity="start"
            android:background="@color/arion_darkgray"
            android:fitsSystemWindows="true"
            app:headerLayout="@layout/navdrawer_header"
            app:itemBackground="@drawable/nav_drawer_selector"
            app:itemIconTint="#fff"
            app:itemTextColor="#fff"
            app:menu="@menu/navdrawer_menu"
            app:theme="@style/custom_navDrawer_style" />

    </android.support.v4.widget.DrawerLayout>
</LinearLayout>
<?xml version="1.0" encoding="utf-8"?>
<android.support.design.widget.CoordinatorLayout 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=".MyHorseActivity">

    <android.support.design.widget.AppBarLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content">

        <android.support.v7.widget.Toolbar
            android:id="@+id/myhorse_toolbar"
            android:layout_width="match_parent"
            android:layout_height="?attr/actionBarSize"
            android:background="@color/arion_darkblue">

            <RelativeLayout
                android:id="@+id/myhorse_toolbar_innerlayout"
                android:layout_width="match_parent"
                android:layout_height="?attr/actionBarSize"
                android:background="@android:color/transparent">

                <TextView
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_centerInParent="true"
                    android:paddingRight="70dp"
                    android:text="My Horse"
                    android:textColor="#fff"
                    android:textSize="24sp" />

                <ImageView
                    android:layout_width="15dp"
                    android:layout_height="15dp"
                    android:layout_alignParentRight="true"
                    android:layout_centerInParent="true"
                    android:layout_marginRight="10dp"
                    android:background="@drawable/circle_shape"
                    android:backgroundTint="#ff0000" />
            </RelativeLayout>

        </android.support.v7.widget.Toolbar>

        <include
            layout="@layout/divider_lightblue"
            android:layout_width="match_parent"
            android:layout_height="1dp"
            android:layout_alignParentBottom="true" />
    </android.support.design.widget.AppBarLayout>
</android.support.design.widget.CoordinatorLayout>

我使用下面的xml文件实现了您的要求。但这样,抽屉就会同时在“状态栏”和“工具栏”下方打开



我同意indramurari的观点。看不到所有的xml代码就无法准确地说出断点。如何尝试使用线性布局作为indramurarimentioned@Umanda这是一个语法错误,现在你可以看到整个代码它不工作。单击菜单按钮时,我的NavigationView不可见。请再次查看问题。我刚刚编辑了所有相关的代码我相信indramurari回答了你的问题。您只需要使用线性布局作为父标记。并在其中使用工具栏和抽屉布局!它不起作用。单击菜单按钮时,我的NavigationView不可见。然后使用上面提供的xml代码。listview是此处从左侧打开的导航视图。从活动中填充此ListView,它应该可以正常工作。