简体   繁体   English

使用Android设计支持库中的NavigationView

[英]Using NavigationView from Android Design Support Library

I'm trying to follow this tutorial to use the new DrawerLayout from the Design Support Library. 我正在尝试按照本教程使用设计支持库中的新DrawerLayout。

It seems that the Android studio isn't recognizing the NavigationView Layout. 似乎Android工作室没有识别NavigationView布局。

This is my main_activity layout: 这是我的main_activity布局:

<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: 当我试图运行该项目时,我收到了下一个错误:

Error: (19) No resource identifier found for attribute 'headerLayout' 错误:(19)找不到属性'headerLayout'的资源标识符

But I do have this drawer_header xml file 但我确实有这个drawer_header xml文件

My bad! 我的错!

You should, of course, import the android support design lib to your project. 当然,您应该将android支持设计库导入到您的项目中。

So the 'dependencies' area in the gradle (app) should look like that: 因此,gradle(app)中的“依赖项”区域应该如下所示:

dependencies {
    compile fileTree(dir: 'libs', include: ['*.jar'])
    compile 'com.android.support:appcompat-v7:22.2.0'
    compile 'com.android.support:design:22.2.0'
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM