【问题标题】:Navigationview and DrawerLayout can not resolveNavigationview 和 DrawerLayout 无法解析
【发布时间】:2018-04-19 09:20:52
【问题描述】:

我正在尝试在代码中使用DrawerLayout 对象或NavigationView 对象,但android studio 无法解析。

这是Build.gradle 我正在使用安卓工作室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'
    }

我会感谢任何帮助

【问题讨论】:

标签: android drawerlayout navigationview


【解决方案1】:

您必须添加support-v4 库,您只导入support

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'

确保您将其导入以使用 NavigationDrawer

import android.support.design.widget.NavigationView;

确保您将其导入以使用 DrawerLayout

import android.support.v4.widget.DrawerLayout;

【讨论】:

  • 编辑了我的答案
【解决方案2】:

您需要将此依赖项添加到您的 gradle 文件中:

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

【讨论】:

    【解决方案3】:

    你需要包含

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

    使用这些依赖项的最新版本

    【讨论】:

      【解决方案4】:

      确保您的 AppCompat 库和设计支持库在 Gradle 中具有相同的版本。

      除此之外,如果您使用的是 androidX,您的设计库将如下所示

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

      你需要使用这个调用 NavigationView

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

      而不是旧的设计支持库调用,即

      <android.support.design.widget.NavigationView
       ...
      />
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2018-06-11
        • 1970-01-01
        • 2015-08-25
        • 2013-06-07
        相关资源
        最近更新 更多