javaandroidxmlkotlincardview

Android CardView white color below card


I have designed a custom component that inherits from cardview. For some reason, it shows a kind of white layout under the card that looks wrong. I have marked it with a red rectangle in the image.

Preview

<androidx.cardview.widget.CardView xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginHorizontal="4dp"
android:layout_marginVertical="4dp"
app:cardBackgroundColor="@color/ride_sys_color_surface_medium"
app:cardCornerRadius="@dimen/ride_sys_border_radius_container_large"
app:cardElevation="@dimen/cardview_default_elevation"
app:cardPreventCornerOverlap="true"
app:contentPadding="0dp"> ...
 </androidx.cardview.widget.CardView>

Solution

  • Use this:

     app:cardElevation="0dp"
    

    app:cardElevation is used to set the height of the shadow (elevation) around the CardView. It creates a shadow effect for the CardView. When you set it to 0dp, it means you are turning off the shadow.