0

I have a card view with a transparent background color and an elevation of 4dp.

It seems that there's no way to block the shadow from being visible inside the transparent card. I keep getting a weird outline which must be the shadow drawn underneath.

Is there any way (that works on API 21 and above) to only draw the shadow outside of my card so I can use transparent colors without artifacts?

card view STYLE xml

<style name="GridCard" parent="CardView">
        <item name="cardCornerRadius">4dp</item>
        <item name="cardElevation">4dp</item>
        <item name="cardUseCompatPadding">true</item>
        <item name="android:layout_marginLeft">8dp</item>
        <item name="android:layout_marginRight">8dp</item>
        <item name="android:layout_marginTop">16dp</item>
        <item name="cardBackgroundColor">@color/white_70</item>
</style>

white_70 is #50FFFFFF

here's what it looks like (weird border caused by the shadow):

here's what it looks like. weird border caused by the shadow

2
  • 1
    Can you provide images and xml code? Commented May 17, 2017 at 14:29
  • Just added them to the post. Commented May 17, 2017 at 14:43

1 Answer 1

0

Just use cardUseCompatPadding as false to remove inner padding and shadow.

Try this style:

<style name="GridCard" parent="CardView">
    <item name="cardCornerRadius">4dp</item>
    <item name="cardElevation">4dp</item>
    <item name="cardUseCompatPadding">false</item>
    <item name="android:layout_marginLeft">8dp</item>
    <item name="android:layout_marginRight">8dp</item>
    <item name="android:layout_marginTop">16dp</item>
    <item name="cardBackgroundColor">@color/white_70</item>
</style>
Sign up to request clarification or add additional context in comments.

2 Comments

Post your cardview xml and related resources and also post the style of "CardView"
I just found there was also a backgroundTint set in the cardView's xml. I took it out and now it works as you suggested!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.