Skip to content Skip to sidebar Skip to footer

Android Cardview With Rounded Corners Displays Grey Corners

I'm inflating a custom layout with CardView inside the layout. The rounded corners are displayed as expected but I also get grey background behind the corners. The code is simple,

Solution 1:

It is because of shadow, you need to give space to cardview to show full shadow. Add android:layout_margin="5dp" to CardView and you will see that the "grey" color is cut shadow.

Solution is adding app:cardUseCompatPadding="true" to CardView and it will give needed spacing.

Solution 2:

Try this...

Just set 0 value to app:cardElevation

.....
<android.support.v7.widget.CardViewandroid:layout_width="match_parent"android:layout_height="wrap_content"app:cardBackgroundColor="@android:color/white"app:cardCornerRadius="6dp"app:cardElevation="0dp">
.....

OR you can call cardView.setCardElevation(0) to disable shadow programmatically.

Solution 3:

Remove the parent RelativeLayout that is wrapping the CardView and you are good to go. Just like this:

<?xml version="1.0" encoding="utf-8"?><android.support.v7.widget.CardViewxmlns:android="http://schemas.android.com/apk/res/android"xmlns:app="http://schemas.android.com/apk/res-auto"android:layout_width="match_parent"android:layout_height="wrap_content"app:cardBackgroundColor="@android:color/white"app:cardCornerRadius="6dp"app:cardElevation="5dp"><RelativeLayoutandroid:layout_width="match_parent"android:layout_height="match_parent"android:background="@android:color/transparent"><TextViewandroid:id="@+id/tvProgress"android:layout_width="wrap_content"android:layout_height="wrap_content"android:layout_alignParentLeft="true"android:layout_alignParentStart="true"android:layout_centerVertical="true"android:layout_toLeftOf="@+id/ivIcon"android:layout_toStartOf="@+id/ivIcon"android:background="@android:color/transparent"android:padding="@dimen/elementPaddingSmall"android:text="Initial Discussion"android:textAppearance="?android:attr/textAppearanceMedium"android:textColor="@android:color/black"/><ImageViewandroid:id="@+id/ivIcon"android:layout_width="50dp"android:layout_height="50dp"android:layout_alignParentEnd="true"android:layout_alignParentRight="true"android:background="@color/lightBrown"android:scaleType="centerInside"android:src="@drawable/ic_checkmark_circle"/></RelativeLayout></android.support.v7.widget.CardView>

Solution 4:

If someone faces the problem when the edges' color is darker than you set, it could happen if you set the color in #AARRGGBB format. To fix this issue, just set the color in the normal #RRGGBB format.

Solution 5:

Change app:cardUseCompatPadding="true" to card_view:cardUseCompatPadding="true"

Post a Comment for "Android Cardview With Rounded Corners Displays Grey Corners"