motis10 motis10 - 1 month ago 31
Android Question

Android 4.4 remove shadow from CardView

I tried to remove the shadow from the Cardview.

I used android support v7 Cardview on android v4.4.2


My layout look:

<android.support.v7.widget.CardView
android:id="@+id/cardContainer"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@null"
card_view:cardBackgroundColor="@color/transparent"
card_view:cardCornerRadius="0dp"
card_view:cardElevation="0dp"
card_view:cardPreventCornerOverlap="false"
card_view:contentPadding="0dp">

<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">

<include layout="@layout/include_profile_header" />

<include layout="@layout/include_profile_footer" />

</RelativeLayout>

</android.support.v7.widget.CardView>


As you can see i used:

card_view:cardElevation="0dp"


Tried so far:

android:background="@null"


But still you can see in the image i attached the top shadow that showed.

CardView Shadow

Answer

You cannot remove the shadow from the cardview in 4.4. Anything below 5.0 elevation does nothing so all the cardview is in 4.4 is an image with a shadow

To create a card with a shadow, use the card_view:cardElevation attribute. CardView uses real elevation and dynamic shadows on Android 5.0 (API level 21) and above and falls back to a programmatic shadow implementation on earlier versions. For more information, see Maintaining Compatibility.

http://developer.android.com/training/material/lists-cards.html#CardView

Comments