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.
'com.google.android.material:material:1.0.0'
is in my dependencies and gradle syncs with no errorsMaterialButton
on the same XML/Activity com.google.android.material.switchmaterial.SwitchMaterial
in xmlcom.google.android.material.switchmaterial.SwitchMaterial
when trying to add to activity java unitCannot find SwitchMaterial
even though other components are there
app 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
<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.
Currently
implementation 'com.google.android.material:material:1.1.0'