[英]error: package android.support.design.widget does not exist import android.support.design.widget.FloatingActionButton;
I am new to android.我是安卓新手。 I was trying to run code.我试图运行代码。 I get the following error.我收到以下错误。
error: package android.support.design.widget does not exist import android.support.design.widget.FloatingActionButton;
Please help to resolve it.请帮助解决它。
Here is the code myActivity.java -->这是代码 myActivity.java -->
import android.support.design.widget.FloatingActionButton;
import android.support.v7.widget.Toolbar;
Here is the build.gradle--->这是 build.gradle --->
apply plugin: 'com.android.application'
apply plugin: 'com.google.gms.google-services'
android {
compileSdkVersion 30
buildToolsVersion "30.0.2"
defaultConfig {
applicationId "com.education"
minSdkVersion 19
targetSdkVersion 30
versionCode 1
versionName "1.0"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
useLibrary 'org.apache.http.legacy'
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}
}
repositories {
maven { url "https://jitpack.io" }
}
dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
testImplementation 'junit:junit:4.12'
implementation 'androidx.appcompat:appcompat:1.1.0'
implementation 'com.google.android.material:material:1.1.0'
implementation 'com.nostra13.universalimageloader:universal-image-loader:1.9.5'
implementation "com.google.android.gms:play-services-gcm:16.0.0"
implementation 'androidx.legacy:legacy-support-v4:1.0.0'
implementation 'androidx.appcompat:appcompat:1.0.2'
implementation 'androidx.constraintlayout:constraintlayout:1.1.3'
implementation 'androidx.legacy:legacy-support-v4:1.0.0'
implementation 'com.google.android.material:material:1.1.0-alpha04'
}
The problem is that you're using Androidx with Material Design Library and FloatingButton has been moved to Material UI.问题是您使用的是带有 Material Design Library 的 Androidx,并且 FloatingButton 已移至 Material UI。 So, now you use it as所以,现在你把它用作
com.google.android.material.floatingactionbutton.FloatingActionButton
and not as android.support.design.widget.FloatingActionButton
.而不是android.support.design.widget.FloatingActionButton
。
So change your code as :因此,将您的代码更改为:
import com.google.android.material.floatingactionbutton.FloatingActionButton;
import androidx.appcompat.widget.Toolbar;
Also, this FloatingButton
is a part of Material Design library now which you've mentioned two times in your build.gradle(app)
file as :此外,这个FloatingButton
现在是 Material Design 库的一部分,您在build.gradle(app)
文件中两次提到:
implementation 'com.google.android.material:material:1.1.0'
...
implementation 'com.google.android.material:material:1.1.0-alpha04'
Remove first one as the second is more upto date.删除第一个,因为第二个是最新的。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.