1

When i run my code on api 28 i do not see this white border along the inner edges of the cardview. but on api 19 i get the following rendered:

enter image description here

My desire is for the color to entirely fill the cardview, and it should clip the corners so i keep the desired rounded effect. here is the simple demo code showing its not working:

    <?xml version="1.0" encoding="utf-8"?>
<com.google.android.material.card.MaterialCardView xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:layout_width="300dp"
    android:layout_height="170dp"
    android:theme="@style/Theme.MaterialComponents.Light"
    app:cardBackgroundColor="@android:color/white"
    app:cardCornerRadius="8dp"
    app:cardElevation="4dp"
    app:rippleColor="@android:color/transparent"
    app:strokeWidth="0dp">

    <ImageView
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:background="@android:color/holo_blue_dark" />

</com.google.android.material.card.MaterialCardView>

note: take a look at what it looks like when rendered on api 28, its exactly what i desire:

enter image description here

UPDATE: I ADJUSTED

using app:cardPreventCornerOverlap="false" , but makes it not rounded. when i put a border around it its not contained in the border now.

can someone suggest :

enter image description here

j2emanue
  • 60,549
  • 65
  • 286
  • 456

2 Answers2

1

Just set app:cardPreventCornerOverlap="false" in your xml

  <?xml version="1.0" encoding="utf-8"?>
<com.google.android.material.card.MaterialCardView xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:layout_width="300dp"
    android:layout_height="170dp"
    android:theme="@style/Theme.MaterialComponents.Light"
    app:cardBackgroundColor="@android:color/white"
    app:cardCornerRadius="8dp"
    app:cardElevation="4dp"
    app:rippleColor="@android:color/transparent"
    app:strokeWidth="0dp"
    app:cardPreventCornerOverlap="false" >

    <ImageView
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:background="@android:color/holo_blue_dark" />

</com.google.android.material.card.MaterialCardView>
Sujan Poudel
  • 794
  • 5
  • 16
-1

i ended up creating a white border that i use ..so i set the strokeColor to white if its below api 19. that seems to be the best i can do . and i do set app:cardPreventCornerOverlap="true" ...its not perfect but achieving elevation on lolipop is a dream come true with this materialCardView.

j2emanue
  • 60,549
  • 65
  • 286
  • 456