16

I am trying to add NavigationView in my layout as below:

<RelativeLayout 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:paddingBottom="@dimen/activity_vertical_margin"
    android:paddingLeft="@dimen/activity_horizontal_margin"
    android:paddingRight="@dimen/activity_horizontal_margin"
    android:paddingTop="@dimen/activity_vertical_margin">


    <android.support.v4.widget.DrawerLayout xmlns:android="http://schemas.android.com/apk/res/android"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:fitsSystemWindows="true">

        <TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="@string/hello_world" />

        <android.support.design.widget.NavigationView
            xmlns:app="http://schemas.android.com/apk/res-auto"
            xmlns:android="http://schemas.android.com/apk/res/android"
            android:layout_width="wrap_content"
            android:layout_height="match_parent"
            android:layout_gravity="start"
            app:menu="@menu/drawer" />

    </android.support.v4.widget.DrawerLayout>
</RelativeLayout>

But the problem is I am getting an error during compile as below:

C:\Users\IBM_ADMIN\Documents\Androidprojects\supporttest\app\src\main\res\layout\activity_main.xml
Error:(22) No resource identifier found for attribute 'menu' in package 'ranjithnair02.com.supporttest'
Error:Execution failed for task ':app:processDebugResources'.
> com.android.ide.common.process.ProcessException: org.gradle.process.internal.ExecException: Process 'command 'C:\Users\IBM_ADMIN\Documents\android-studio\sdk\build-tools\22.0.1\aapt.exe'' finished with non-zero exit value 1
Information:BUILD FAILED

I have added the menu item in menu/drawer.xml.

<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    tools:context=".MainActivity">

    <group android:checkableBehavior="single">

        <item
            android:id="@+id/navigation_item_1"
            android:checked="true"
            android:icon="@drawable/abc_tab_indicator_mtrl_alpha"
            android:title="First" />

        <item
            android:id="@+id/navigation_item_2"
            android:icon="@drawable/abc_btn_check_material"
            android:title="Second" />
      </group>
</menu>
Psypher
  • 10,717
  • 12
  • 59
  • 83
  • [https://pratamawijaya.com/programming/android-programming/after-google-io-2015-android-design-support-library-demo](https://pratamawijaya.com/programming/android-programming/after-google-io-2015-android-design-support-library-demo) – M D May 30 '15 at 08:36
  • Did you add your Gradle dependency? `compile 'com.android.support:design:22.2.0'` – hungryghost May 30 '15 at 11:00
  • Did you try cleaning your project? Closing & opening Android Studio? That helped me. – Nick H May 31 '15 at 00:45

2 Answers2

46

Make sure you have the correct dependency to the Android Design Support Library. It's easy to choose the wrong one - because it seems that Google posted two different dependency strings:

At the time of this answer, the Android developer blog (and the comment by user hungryghost) had the correct dependency string, while the dependency string on the Support library homepage did not work.

Use this one: compile 'com.android.support:design:26.1.0'

Note that the version is 22.2.0 (wrong: 22.0.0) and that the package is called design (wrong: support-design)

After these changes use the Android Studio menu "Rebuild project", or the "Sync" button that appears sometimes after changing the gradle file. That finally made it work for me.

IgorGanapolsky
  • 26,189
  • 23
  • 116
  • 147
Patrick
  • 4,720
  • 4
  • 41
  • 71
  • Wouldn't **com.android.support:appcompat-v7** include design lib? – IgorGanapolsky Oct 16 '17 at 21:14
  • 1
    @IgorGanapolsky Not according to maven (mvn dependency:tree) when used on a test project depending on appcompat-v7. Also, there is no indication of it on the support library website: https://developer.android.com/topic/libraries/support-library/packages.html – Patrick Oct 17 '17 at 06:10
8

Add the below line to app gradle file.

dependencies { .....

  • implementation 'com.android.support:design:26.1.0'

....

}

for gradle version 3.0.1

Dino Sunny
  • 921
  • 1
  • 10
  • 18