Java 无法导入 android.support.design.widget.NavigationView

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/32532554/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-11 12:43:38  来源:igfitidea点击:

Unable to import android.support.design.widget.NavigationView

javaandroidnavigationview

提问by Dushyant Suthar

I want to have navigation drawer in my application so I am following a tutorial here, in which he has imported the NavigationViewlibrary within his project. When I import that library, an error pops up: 'can not resolve'. So again when I hover over the importstatement and select 'find jar on web', a message shows saying 'no such library found'.

我想在我的应用程序中有导航抽屉,所以我在这里学习了一个教程,他NavigationView在他的项目中导入了库。当我导入该库时,会弹出一个错误:“无法解析”。因此,当我再次将鼠标悬停在该import语句上并选择“在网络上查找 jar”时,会显示一条消息,显示“未找到此类库”。

采纳答案by Mrdrew

I am also facing the same problem and i found a solution by adding the following code to build.gradle

我也面临同样的问题,我通过将以下代码添加到 build.gradle 找到了解决方案

compile 'com.android.support:design:22.2.0'

I also adjusted my targetSdk in the build.gradle file to 22 and i was able to succesfully import the NavigationView without any problem.

我还将 build.gradle 文件中的 targetSdk 调整为 22,并且能够成功导入 NavigationView,没有任何问题。

回答by Milad Nouri

before importing support library, Make sure you have downloaded Android Support Repository using SDK Manager.

在导入支持库之前,请确保您已使用 SDK Manager 下载了 Android Support Repository。

回答by Александр Тихонович

If you have this error with compile design:22 or higher just restart your Android Studio.

如果您在 compile design:22 或更高版本中遇到此错误,只需重新启动您的 Android Studio。

回答by bhaskarc

If in your app build.gradlefile compileSdkVersionreads as say 28, then add the following line under dependencies:

如果在您的应用程序build.gradle文件中compileSdkVersion读取为 say 28,则在依赖项下添加以下行:

dependencies {
   --other dependencies
   implementation 'com.android.support:design:28.0.0'
 }

Change the version number according to your compiledSdkVersion

根据您的情况更改版本号 compiledSdkVersion

Then re-build your project. This brings in the required dependency.

然后重新构建您的项目。这带来了所需的依赖性。