5

我正在尝试按照本教程使用设计支持库中的新 DrawerLayout。

似乎 Android 工作室无法识别 NavigationView 布局。

这是我的 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>

当我尝试运行该项目时,我遇到了下一个错误:

错误:(19) 未找到属性“headerLayout”的资源标识符

但我确实有这个drawer_header xml文件

4

1 回答 1

17

我的错!

当然,您应该将 android 支持设计库导入您的项目。

所以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'
}
于 2015-06-14T00:47:42.087 回答