android - 使用 Android 设计支持库中的 NavigationView

标签 android android-studio android-support-library drawerlayout navigationview

我正在尝试关注 this tutorial使用设计支持库中的新 DrawerLayout。

Android studio 似乎无法识别 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>

当我尝试运行该项目时,出现下一个错误:

Error: (19) No resource identifier found for attribute 'headerLayout'

但我确实有这个 drawer_header xml 文件

最佳答案

我的错!

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

因此 gradle(应用程序)中的“依赖项”区域应该如下所示:

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 - 使用 Android 设计支持库中的 NavigationView,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30824919/

相关文章:

android - 为什么 EmojiCompat 只能在 Android 19+ 上使用?

android - 如何在同一 Activity 上使用菜单和 onKeyDown()

android - 无法启动Android工作室

java - 我可以在 Android 中将 FloatingActionButton 转换为 ImageButton 吗?

android - 重复的 zip 条目 [classes.jar :android/support/design/widget/CoordinatorLayout$Behavior. 类]

android - 即使添加存储库后也无法解析NavigationView

当我退出应用程序时 Android 服务停止

android - TextView 与 breakStrategy ="balanced"和 layout_width ="wrap_content"一起工作时出错

java - 将文本动态添加到 Android Studio 中的输入字段

android - 如何修复 Android Studio 中的错误 "Unable to open debugger port "?