DrawerLayout and NavigationView - attribute 'menu' not found
Asked Answered
N

1

5

I'm trying to add a Navigation Menu to an existing project in 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.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"

This seems to also have the effect of giving me the error Cannot resolve symbol R in my MainActivity.java file.

Anyway, any help is very much appreciated!

Nambypamby answered 31/12, 2017 at 9:59 Comment(0)
T
8

Do you have the compile 'com.android.support:design:27.0.2' in your build.gradle file? If not, try to add it.

Trager answered 31/12, 2017 at 10:24 Comment(3)
Thanks, this worked to get rid of the error. I did get another one, however, which I solved by creating the res/menu directory and putting a my_navigation_files.xml file inside it.Nambypamby
If you are using gradle 3.0 use implement instead of compile. More on the topic here: https://mcmap.net/q/45413/-what-39-s-the-difference-between-implementation-api-and-compile-in-gradleTrager
if you are using AndroidX: implementation 'com.google.android.material:material:1.0.0'Spirograph

© 2022 - 2024 — McMap. All rights reserved.