Android material google 库中缺少组件
Missing components in material google library on Android
我正在尝试在 Android 项目中使用 SwitchMaterial
组件,但是 Android studio 在设计时找不到它,因此无法将其包含在我的 xml 布局中在运行时导致 ClassNotFoundException
。
- 最近的 Android 工作室项目因此已经使用 AndroidX
设置
'com.google.android.material:material:1.0.0'
在我的依赖项中并且 gradle 同步没有错误
- 存在一些其他 Material 组件,例如我在同一个 XML/Activity
上使用 MaterialButton
- 无法在 xml
中找到 com.google.android.material.switchmaterial.SwitchMaterial
- 尝试添加到 activity java 单元时无法导入
com.google.android.material.switchmaterial.SwitchMaterial
- 构建设置:编译 SDK = 29 构建工具 = 29.0.2 Min SDK = 19 目标 SDK = 29
- 没有混淆器规则设置(根本)所以不应该弄乱它
- 花了一个小时谷歌搜索答案 - 没有关于 SO 或 Android / Material 文档
无法找到 SwitchMaterial
即使有其他组件
应用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布局
<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" />
感谢任何帮助。我不明白为什么会缺少组件。
您需要 material 组件库的版本 1.1.0。
目前
implementation 'com.google.android.material:material:1.1.0'
我正在尝试在 Android 项目中使用 SwitchMaterial
组件,但是 Android studio 在设计时找不到它,因此无法将其包含在我的 xml 布局中在运行时导致 ClassNotFoundException
。
- 最近的 Android 工作室项目因此已经使用 AndroidX 设置
'com.google.android.material:material:1.0.0'
在我的依赖项中并且 gradle 同步没有错误- 存在一些其他 Material 组件,例如我在同一个 XML/Activity 上使用
- 无法在 xml 中找到
- 尝试添加到 activity java 单元时无法导入
com.google.android.material.switchmaterial.SwitchMaterial
- 构建设置:编译 SDK = 29 构建工具 = 29.0.2 Min SDK = 19 目标 SDK = 29
- 没有混淆器规则设置(根本)所以不应该弄乱它
- 花了一个小时谷歌搜索答案 - 没有关于 SO 或 Android / Material 文档
MaterialButton
com.google.android.material.switchmaterial.SwitchMaterial
无法找到 SwitchMaterial
即使有其他组件
应用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布局
<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" />
感谢任何帮助。我不明白为什么会缺少组件。
您需要 material 组件库的版本 1.1.0。
目前
implementation 'com.google.android.material:material:1.1.0'