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
和旧的导航抽屉设置,所以我想继续使用它。