What's the difference between the CardView from com.google.android.material and android.support.v7.widget
S

3

41

I'd like to know the difference between both widgets android.support.v7.widget.CardView which is added using Android Studio IDE components palette and com.google.android.material.card.MaterialCardView which is used on Material Design documentation.

Are they two libraries that contains the same widget? Which one should I use and how to take this decision?

I tried to read more the developers.android documentation, but the docs on developer.android are really big with many version and I'm yet a bit confused and couldn't find a good explanation between all of these versions, the history of it all and how it got there. Does someone feel happy to gives me a insight about this history?

Material design documentation usage:

<com.google.android.material.card.MaterialCardView
    android:layout_width="match_parent"
   android:layout_height="wrap_content">
</com.google.android.material.card.MaterialCardView>

Source: https://material.io/develop/android/components/material-card-view/

The CardView XML added when using Android Studio:

<android.support.v7.widget.CardView
    android:layout_width="match_parent"
    android:layout_height="wrap_content">
</android.support.v7.widget.CardView>
Sing answered 10/4, 2019 at 1:17 Comment(4)
That's material layout with much more clean look.Enlighten
So, is it recommended to use android.support/androidx (as I read, the version that the old support library) instead of following the material guide that uses com.google.android.material?Accusal
No I also recommend Material themes. I was just explaining what's different in material and support library.Enlighten
Note that com.google.android.material.card.MaterialCardView extends androidx.cardview.widget.CardView. See developer.android.com/reference/com/google/android/material/…Allomorphism
A
90

There are 3 versions:

  • android.support.v7.widget.CardView: it is provided by the old support libraries and it is deprecated.

  • androidx.cardview.widget.CardView it is the androidx version and it replaced the support libraries.
    To use it you have to add the dependency implementation 'androidx.cardview:cardview:x.x.x'.

  • com.google.android.material.card.MaterialCardView is provided by the Material Components Library. To use it you have to add the dependency implementation 'com.google.android.material:material:1.1.0'.

The MaterialCardView extends the androidx.cardview.widget.CardView and introduces some changes as the use of a MaterialShapeDrawable as background (it allows shaping and elevation overlays for Dark Themes).
Also MaterialCardView supports checking and dragging.

Alyciaalyda answered 23/5, 2020 at 15:16 Comment(2)
This should be as the best answer. It provides all the context to fully understand the differences between this components.Reneta
com.google.android.material.card.MaterialCardView also has a foreground selector by default.Euromarket
S
18

I made a research in the last days about the history of Android libraries and I've got a conclusion that I'd like to share:

  1. The component android.support.v7.widget.CardView is part of an old library and it's recommended to be replaced with com.google.android.material.card.MaterialCardView
  2. Android support library (android.support.*) is an old library that was replace by the new Android X Library in 2018 (which is part of Jetpack Library) and also by material components android

References:

https://medium.com/@neerajmoudgil/upgrading-to-new-android-material-design-components-e62ddb03c3d2

https://developer.android.com/reference (It's big, but worth to take a look for beginners who would like to understand the history of Android Libraries and also about all of the Android Versions)

Sing answered 16/4, 2019 at 4:31 Comment(2)
What about androidx.cardview.widget.CardView?Traffic
It is a androidx version of android.cardview @TrafficGenia
J
8

According to Material Design docs

MaterialCardView is a customizable component based on CardView from the Android Support Library. MaterialCardView provides all of the features of CardView, but adds attributes for customizing the stroke and uses an updated Material style by default.

Jozef answered 24/9, 2019 at 20:19 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.