1

I am trying to use DrawerLayout object or NavigationView Object in code but android studio can not resolve.

This is Build.gradle I am using android studio 3.1.1

 dependencies {
    implementation 'com.android.support:design:26.1.0'
    implementation 'com.android.support:appcompat-v7:26.1.0'
    implementation fileTree(include: ['*.jar'], dir: 'libs')
    implementation 'com.android.support.constraint:constraint-layout:1.0.2'
    testImplementation 'junit:junit:4.12'
    androidTestImplementation 'com.android.support.test:runner:0.5'
    androidTestImplementation 'com.android.support.test.espresso:espresso- 
   core:2.2.2'
    }

I will Appreciate any help

Jay Rathod
  • 11,131
  • 6
  • 34
  • 58
Shahram1974
  • 29
  • 1
  • 2

4 Answers4

2

You have to add support-v4 library, you are imporing only support library

implementation 'com.android.support:appcompat-v7:27.1.1'
implementation 'com.android.support:support-v4:27.1.1'
implementation 'com.android.support:design:27.1.1'
implementation 'com.android.support.constraint:constraint-layout:1.1.0'

Make sure you are importing this to use NavigationDrawer

import android.support.design.widget.NavigationView;

Make sure you are importing this to use DrawerLayout

import android.support.v4.widget.DrawerLayout;
Skizo-ozᴉʞS ツ
  • 19,464
  • 18
  • 81
  • 148
2

You Need to add this dependency to your gradle file:

'com.google.android.material:material:1.1.0'

MostafaMashayekhi
  • 27,359
  • 3
  • 21
  • 39
Ankur10
  • 21
  • 2
0

u need to include

compile "com.android.support:appcompat-v7:21.0.+"
compile "com.android.support:appcompat-v4:21.0.+"
compile "com.android.support:design:21.0.+"

use latest versions of these dependencies

Ak9637
  • 990
  • 6
  • 12
0

Make sure that your AppCompat library and Design Support library have the same version in your Gradle.

In addition to that, if you are using androidX your design library is going to be the following

implementation 'com.google.android.material:material:{Your-Version}'

and you need to use this call to NavigationView

<com.google.android.material.navigation.NavigationView
 ...
/>

rather than the old Design Support library call which is

<android.support.design.widget.NavigationView
 ...
/>
jameseronious
  • 219
  • 2
  • 5