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!

JThistle
  • 128
  • 1
  • 9

1 Answers1

8

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

Sal
  • 814
  • 6
  • 12
  • 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. – JThistle Dec 31 '17 at 10:47
  • If you are using gradle 3.0 use implement instead of compile. More on the topic here: https://stackoverflow.com/a/44493379/8700123 – Sal Dec 31 '17 at 18:43
  • 5
    if you are using AndroidX: `implementation 'com.google.android.material:material:1.0.0'` – Gary McGowan Apr 21 '19 at 14:41