Reputation: 280
I'm trying to test my skills on new Google Material components.
But for now I am encountering a problem with MaterialCardView
The building process tells me
The style on this component requires your app theme to be Theme.AppCompat
[..]
at com.google.android.material.card.MaterialCardView.<init>
With this clue I added
style="@style/Theme.AppCompat"
& android:theme="@style/Theme.AppCompat"
to the MaterialCardView
and also to my Activity in the manifest.
I tried also to change my Acitivity to AppCompatActivity but without any success.
I also tried to set styles told by material.io documentation but without success !
Have you some clues?
Thanks
Upvotes: 10
Views: 2038
Reputation: 38243
According to Material Components 1.2.1 you need to do this:
implementation 'com.google.android.material:material:1.2.1'
compileSdkVersion 30
AppCompatActivity
(or use AppCompatDelegate
)The easiest way to get started is for your current theme to extend Theme.MaterialComponents.*.Bridge
instead of Theme.AppCompat.*
.
Additionally you'll need to override the following attribute in your theme, otherwise the card color will be broken:
<style name="AppTheme" parent="Theme.MaterialComponents.Light.DarkActionBar.Bridge">
<item name="elevationOverlayEnabled">false</item>
</style>
Don't set android:theme="@style/Theme.MaterialComponents"
on the card. You'll lose color information (primary, secondary, accent,...) from your theme on every widget inside the card.
Don't set style="@style/Theme.MaterialComponents
on the card. Don't mix themes and styles.
Upvotes: 5