从Android设计支持库使用NavigationView [英] Using NavigationView from Android Design Support Library
问题描述
我试图按照本教程使用新DrawerLayout从设计支持库。
I'm trying to follow this tutorial to use the new DrawerLayout from the Design Support Library.
看来,Android的工作室是不承认的NavigationView布局。
It seems that the Android studio isn't recognizing the NavigationView Layout.
这是我的main_activity布局:
This is my main_activity layout:
<android.support.v4.widget.DrawerLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:padding="20dp">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Hello"/>
</LinearLayout>
<android.support.design.widget.NavigationView
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_gravity="start"
app:headerLayout="@layout/drawer_header"
app:menu="@menu/drawer_menu"/>
</android.support.v4.widget.DrawerLayout>
而当我试图运行项目,我得到了一个错误:
And when I'm trying to run the project, I'm getting the next error:
错误:(19)未找到属性资源标识符headerLayout
Error: (19) No resource identifier found for attribute 'headerLayout'
不过,我确实有这个drawer_header xml文件
But I do have this drawer_header xml file
推荐答案
我的坏!
您应该的,当然,导入支持Android设计lib添加到您的项目。
You should, of course, import the android support design lib to your project.
所以,'依赖'的gradle这个(应用程序)区域应该看起来像:
So the 'dependencies' area in the gradle (app) should look like that:
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
compile 'com.android.support:appcompat-v7:22.2.0'
compile 'com.android.support:design:22.2.0'
}
这篇关于从Android设计支持库使用NavigationView的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!