Using NavigationView from Android Design Support Library

7.1k views Asked by At

I'm trying to follow this tutorial to use the new DrawerLayout from the Design Support Library.

It seems that the Android studio isn't recognizing the NavigationView Layout.

This is my main_activity layout:

<android.support.v4.widget.DrawerLayout
   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:fitsSystemWindows="true">

   <LinearLayout
       android:layout_width="match_parent"
       android:layout_height="match_parent"
       android:padding="20dp">
       <TextView
           android:layout_width="wrap_content"
           android:layout_height="wrap_content"
           android:text="Hello"/>
   </LinearLayout>

<android.support.design.widget.NavigationView
    android:layout_width="wrap_content"
    android:layout_height="match_parent"
    android:layout_gravity="start"
    app:headerLayout="@layout/drawer_header"
    app:menu="@menu/drawer_menu"/>
</android.support.v4.widget.DrawerLayout>

And when I'm trying to run the project, I'm getting the next error:

Error: (19) No resource identifier found for attribute 'headerLayout'

But I do have this drawer_header xml file

1

There are 1 answers

0
David On

My bad!

You should, of course, import the android support design lib to your project.

So the 'dependencies' area in the gradle (app) should look like that:

dependencies {
    compile fileTree(dir: 'libs', include: ['*.jar'])
    compile 'com.android.support:appcompat-v7:22.2.0'
    compile 'com.android.support:design:22.2.0'
}