简体   繁体   English

DrawerLayout 和 NavigationView - 找不到属性“菜单”

[英]DrawerLayout and NavigationView - attribute 'menu' not found

I'm trying to add a Navigation Menu to an existing project in Android Studio.我正在尝试向 Android Studio 中的现有项目添加导航菜单。 However, while following the instructions on the official website , I added a <android.support.v4.widget.DrawerLayout ... tag around the rest of my view, and under the main ConstraintLayout that has the main activity layout, I put the sample Navigation Draw underneath that:但是,在按照官方网站上的说明进行操作同时,我在视图的其余部分添加了一个<android.support.v4.widget.DrawerLayout ...标记,并在具有主要活动布局的主要 ConstraintLayout 下,我将下面的示例导航绘制:

<android.support.design.widget.NavigationView
        android:id="@+id/navigation"
        android:layout_width="wrap_content"
        android:layout_height="match_parent"
        android:layout_gravity="start"
        app:menu="@menu/my_navigation_items" />

The last line causes some problems though when building:最后一行在构建时会导致一些问题:

Error:error: attribute 'com. ... :menu' not found.

I can't figure out why this is happening.我不明白为什么会这样。 The app part of app:menu is defined in the DrawerLayout tag as: xmlns:app="http://schemas.android.com/apk/res-auto" app:menuapp部分在 DrawerLayout 标签中定义为: xmlns:app="http://schemas.android.com/apk/res-auto"

This seems to also have the effect of giving me the error Cannot resolve symbol R in my MainActivity.java file.这似乎也给我带来了错误Cannot resolve symbol R MainActivity.java 文件中的Cannot resolve symbol R

Anyway, any help is very much appreciated!无论如何,非常感谢任何帮助!

Do you have the compile 'com.android.support:design:27.0.2' in your build.gradle file?你的 build.gradle 文件中有compile 'com.android.support:design:27.0.2'吗? If not, try to add it.如果没有,请尝试添加它。

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

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