Search code examples
androidandroid-cardviewandroid-librarymaterialcardview

MaterialCardView backward compatibility


All MaterialCardView are turning black on pre-Lollipop, specifically API 16 like this:

enter image description here

I tried to make a style for the card, but it's not working, but it works when I'm using CardView.

<android.support.design.card.MaterialCardView
                android:layout_width="match_parent"
                android:layout_height="120dp"
                android:foreground="@color/transparent"
                android:id="@+id/matcard"
                android:background="@color/white"
                app:cardPreventCornerOverlap="false"
                app:cardUseCompatPadding="true"
                app:cardCornerRadius="12dp"
                app:strokeColor="@color/colorPrimary"
                app:strokeWidth="0.5dp"
                android:layout_margin="5dp">
                <LinearLayout
                    android:layout_width="match_parent"
                    android:layout_height="match_parent"
                    android:orientation="horizontal"
                    > ...
 </android.support.design.card.MaterialCardView>

Is there a way to fix this without rewriting my code?

Solved

Problem Solved ! By Migrating to AndroidX


Solution

  • Solved By Migrating to AndroidX & add the new Material Library to gradle :

    implementation 'com.google.android.material:material:1.0.0'