Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

DrawerLayout and NavigationView - attribute 'menu' not found

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!

like image 817
JThistle Avatar asked Dec 31 '17 09:12

JThistle


1 Answers

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

like image 95
Sal Avatar answered Oct 05 '22 16:10

Sal