Cardview elevation is not working with androidx artifacts
Asked Answered
P

2

7

My card view elevation stopped working and showing shadow after I updated my android studio 3.3 and migrating my project to androidx artifacts.

<androidx.cardview.widget.CardView
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:elevation="@dimen/card_margin"
        app:cardCornerRadius="@dimen/card_margin">

        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:orientation="vertical">
               <!--Other Code-->
        </LinearLayout>
    </androidx.cardview.widget.CardView>
Phytopathology answered 21/1, 2019 at 16:6 Comment(0)
S
6

Add app:cardElevation="10dp" property to cardview.

<androidx.cardview.widget.CardView
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:elevation="@dimen/card_margin"
    **app:cardElevation="@dimen/card_margin"**
    app:cardCornerRadius="@dimen/card_margin">

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:orientation="vertical">
           <!--Other Code-->
    </LinearLayout>
</androidx.cardview.widget.CardView>
Sergio answered 12/2, 2019 at 11:17 Comment(0)
B
6

you need to specify app:cardUseCompatPadding="true" in your CardView then set app:cardElevation="4dp" with approbate value

  <androidx.cardview.widget.CardView
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:elevation="12dp"
        app:cardCornerRadius="12dp"
        app:cardUseCompatPadding="true"
        app:cardElevation="4dp">
Banky answered 14/7, 2020 at 12:54 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.