I am using MaterialCardView as my cardview
layout. Now, Android-studio started showing me that instead of current implementation \"com.google.android.mat
The error is in the stacktrace:
Caused by: java.lang.IllegalArgumentException: The style on this component requires your app theme to be Theme.MaterialComponents (or a descendant).
With the version 1.1.0 you have to inherit from a Theme.MaterialComponents.
Change your app theme to
<style name="AppTheme" parent="Theme.MaterialComponents.DayNight">
<!-- .... -->
</style>
It works after changing this <style name="AppTheme" parent="Theme.AppCompat.DayNight>
to <style name="AppTheme" parent="Theme.MaterialComponents.DayNight">
you can just keep it in your materialcardview itself also:
<com.google.android.material.card.MaterialCardView
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:cardCornerRadius="8dp"
**** android:theme="@style/Theme.MaterialComponents.Light" *****
app:cardElevation="8dp">
In my case I just added the android:theme="" attribute and it worked. My Material Card View element is as below -
<com.google.android.material.card.MaterialCardView
android:id="@+id/edit_profile_card"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginStart="@dimen/dp_16"
android:layout_marginTop="@dimen/dp_10"
android:layout_marginEnd="@dimen/dp_16"
android:layout_marginBottom="@dimen/dp_10"
**android:theme="@style/Theme.MaterialComponents.DayNight"**
app:cardCornerRadius="@dimen/dp_10"
app:cardElevation="@dimen/dp_20"
app:state_dragged="false">
....
....
</com.google.android.material.card.MaterialCardView>
You need to change your AppTheme to have it's parent theme as a descendant of MaterialComponent
In your particular case changing the AppTheme from
<style name="AppTheme" parent="Theme.AppCompat.DayNight">
to
<style name="AppTheme" parent="Theme.MaterialComponents.DayNight">
should fix the issue.
If after changing the theme to Theme.MaterialComponents
in the styles.xml didn't work then make sure you have added style tag in the MaterialCard.
style="@style/Widget.MaterialComponents.CardView"