Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/213.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android 如何将标题添加到Google';什么是新的导航视图?_Android_Navigationview - Fatal编程技术网

Android 如何将标题添加到Google';什么是新的导航视图?

Android 如何将标题添加到Google';什么是新的导航视图?,android,navigationview,Android,Navigationview,我正试图将我自己的自定义标题视图添加到谷歌新的导航视图中,但出于某种原因,无论我做什么,Android Studio都会给我一个警告,说包含,这里不允许相对视图。我试过了 <android.support.design.widget.NavigationView android:id="@+id/navigation_drawer" android:layout_width="wrap_content" android:layout_height="match_pa

我正试图将我自己的自定义标题视图添加到谷歌新的
导航视图中
,但出于某种原因,无论我做什么,Android Studio都会给我一个警告,说
包含
,这里不允许
相对视图
。我试过了

<android.support.design.widget.NavigationView
    android:id="@+id/navigation_drawer"
    android:layout_width="wrap_content"
    android:layout_height="match_parent"
    android:layout_gravity="start"
    android:fitsSystemWindows="true">

    <include layout="@layout/nav_drawer_header" />

    <android.support.v7.widget.RecyclerView
        android:id="@+id/nav_list"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:background="#cccc"
        android:choiceMode="singleChoice"
        android:divider="@android:color/transparent"
        android:dividerHeight="0dp"/>
</android.support.design.widget.NavigationView>

但是只有
RecyclerView
显示出来,我不知道还能做什么


我真的很感谢你的帮助。谢谢

您可以使用
app:headerLayout
XML属性向
NavigationView
添加标题:

<android.support.design.widget.NavigationView
    android:id="@+id/navigation_drawer"
    android:layout_width="wrap_content"
    android:layout_height="match_parent"
    android:layout_gravity="start"
    android:fitsSystemWindows="true"
    app:headerLayout="@layout/nav_drawer_header" />

下面演示了设计支持库中导航视图的典型用法。如您所见,NavigationView有一个名为headerLayout的属性来设置其标题视图

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

   <!-- Content -->
   <FrameLayout
        android:id="@+id/content_layout"
        android:layout_width="match_parent"
        android:layout_height="match_parent"/>

   <!-- Drawer -->
    <android.support.design.widget.NavigationView
        android:id="@+id/navigation"
        android:layout_width="240dp"
        android:layout_height="match_parent"
        android:layout_gravity="start"
        app:headerLayout="@layout/drawer_header"
        app:menu="@menu/drawer"/>    
</android.support.v4.widget.DrawerLayout>

我本可以这样做,但我使用的菜单是动态的,我已经在使用
RecyclerView
和旧的导航抽屉设置,所以我想继续使用它。