[英]Missing components in material google library on Android
I am trying to use SwitchMaterial
component within an Android project, however Android studio cannot find it at design time, and including it within my xml layouts causes a ClassNotFoundException
at runtime.我正在尝试在 Android 项目中使用
SwitchMaterial
组件,但是 Android 工作室在设计时找不到它,并且在我的 xml 布局中包含它会在运行时导致ClassNotFoundException
。
'com.google.android.material:material:1.0.0'
is in my dependencies and gradle syncs with no errors 'com.google.android.material:material:1.0.0'
在我的依赖项中,并且 gradle 同步没有错误MaterialButton
on the same XML/ActivityMaterialButton
com.google.android.material.switchmaterial.SwitchMaterial
in xmlcom.google.android.material.switchmaterial.SwitchMaterial
com.google.android.material.switchmaterial.SwitchMaterial
when trying to add to activity java unitcom.google.android.material.switchmaterial.SwitchMaterial
Cannot find SwitchMaterial
even though other components are there即使有其他组件也找不到
SwitchMaterial
app build.gradle应用程序 build.gradle
apply plugin: 'com.android.application'
android {
compileSdkVersion 29
buildToolsVersion "29.0.2"
defaultConfig {
applicationId "my.app.id"
minSdkVersion 19
targetSdkVersion 29
versionCode 1
versionName "0.0.1"
}
buildTypes {
release {
minifyEnabled true
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
}
}
dexOptions {
javaMaxHeapSize "6g"
}
lintOptions {
lintConfig file("lint.xml")
showAll false
}
}
dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation 'androidx.appcompat:appcompat:1.1.0'
implementation 'androidx.constraintlayout:constraintlayout:1.1.3'
implementation 'com.github.bumptech.glide:glide:4.10.0'
implementation 'com.google.android.material:material:1.0.0'
implementation 'com.google.code.gson:gson:2.8.6'
}
XML layout XML布局
<com.google.android.material.switchmaterial.SwitchMaterial
android:id="@+id/login_notificationsSwitchFamily"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="@dimen/margin_10"
android:checked="true"
android:text="Family Friendly"
android:textSize="@dimen/textSize_16" />
Any help is appreciated.任何帮助表示赞赏。 I cannot see why there would be missing components.
我不明白为什么会缺少组件。
You need the version 1.1.0 of the material components library.您需要材料组件库的1.1.0版本。
Currently目前
implementation 'com.google.android.material:material:1.1.0'
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.