android - NavigationView 抛出错误 : No resource identifier found for attribute 'menu' in package

标签 android material-design drawerlayout androiddesignsupport navigationview

我正在尝试在我的布局中添加 NavigationView,如下所示:

<RelativeLayout 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:paddingBottom="@dimen/activity_vertical_margin"
    android:paddingLeft="@dimen/activity_horizontal_margin"
    android:paddingRight="@dimen/activity_horizontal_margin"
    android:paddingTop="@dimen/activity_vertical_margin">


    <android.support.v4.widget.DrawerLayout xmlns:android="http://schemas.android.com/apk/res/android"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:fitsSystemWindows="true">

        <TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="@string/hello_world" />

        <android.support.design.widget.NavigationView
            xmlns:app="http://schemas.android.com/apk/res-auto"
            xmlns:android="http://schemas.android.com/apk/res/android"
            android:layout_width="wrap_content"
            android:layout_height="match_parent"
            android:layout_gravity="start"
            app:menu="@menu/drawer" />

    </android.support.v4.widget.DrawerLayout>
</RelativeLayout>

但问题是我在编译过程中遇到如下错误:

C:\Users\IBM_ADMIN\Documents\Androidprojects\supporttest\app\src\main\res\layout\activity_main.xml
Error:(22) No resource identifier found for attribute 'menu' in package 'ranjithnair02.com.supporttest'
Error:Execution failed for task ':app:processDebugResources'.
> com.android.ide.common.process.ProcessException: org.gradle.process.internal.ExecException: Process 'command 'C:\Users\IBM_ADMIN\Documents\android-studio\sdk\build-tools\22.0.1\aapt.exe'' finished with non-zero exit value 1
Information:BUILD FAILED

我已经在 menu/drawer.xml 中添加了菜单项。

<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    tools:context=".MainActivity">

    <group android:checkableBehavior="single">

        <item
            android:id="@+id/navigation_item_1"
            android:checked="true"
            android:icon="@drawable/abc_tab_indicator_mtrl_alpha"
            android:title="First" />

        <item
            android:id="@+id/navigation_item_2"
            android:icon="@drawable/abc_btn_check_material"
            android:title="Second" />
      </group>
</menu>

最佳答案

确保您对 Android 设计支持库具有正确的依赖关系。 很容易选择错误的——因为 Google 似乎发布了两个不同的依赖字符串:

在回答此问题时,Android developer blog (以及用户饥饿鬼的评论)具有正确的依赖字符串,而 Support library homepage 上的依赖字符串没用。

使用这个: 编译'com.android.support:design:26.1.0'

请注意,版本是 22.2.0(错误:22.0.0)并且包名为 design(错误: 支持设计)

这些更改后,使用 Android Studio 菜单“重建项目”,或更改 gradle 文件后有时出现的“同步”按钮。 这终于使它对我有用。

关于android - NavigationView 抛出错误 : No resource identifier found for attribute 'menu' in package,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30543993/

相关文章:

android - 在android中将数据发布到webview

android - webdriver python 的触摸事件示例?

android - 我的应用程序可以控制哪些设置来节省电池生命周期?

android - 直接在 Android 上写入帧缓冲区

html - 如何在两个接缝之间动态放置 "floating action button"?

android - 我如何为我的 Gridview 实现触摸波纹?

css - 对齐具有可变文本长度的卡片网格中的按钮(Material Design Lite)

android - 带抽屉导航的 PreferenceActivity 抛出空指针异常

android - 为什么我的 DrawerLayout 抽屉标题无法到达状态栏下方?

java - 使用 CoordinatorLayout 时如何消除抽屉导航在工具栏上转换的阴影