3

I have my Card View set up like this:

android:layout_marginTop="2dp"
android:layout_marginLeft="6dp"
android:layout_marginRight="6dp"
card_view:cardCornerRadius="2dp"
card_view:cardElevation="6dp"
card_view:cardUseCompatPadding="true"
card_view:contentPadding="10p"

Without a background color my Card View looks perfect like this:

enter image description here

However, when I add the simple property:

card_view:cardBackgroundColor="#xxxxxxxx"

the shadows change significantly in terms of color, transparency, blur etc.

enter image description here

How might I go about fixing this? I tried using a RelativeLayout as the background and changing the color there, so it wouldn't affect the shadows... but that affected the rounded corners.

Any ideas? Thanks for the help!

Greg Peckory
  • 7,700
  • 21
  • 67
  • 114

4 Answers4

1

I ran into the exact same problem and solved it by removing the alpha portion of my hex code.

Example: #AA333333 removing the AA. Of course use the hex color that you need without the alpha.

Danny Lui
  • 11
  • 1
0

Your idea of RelativeLayout is a good one. Instead of placing the card view in RelativeLayout, add RelativeLayout as CardView child, and than add its content to RelativeLayout, in your case it look like you got single child: TextView.

So change your TextView background color or place it in a RelativeLayout and change RelativeLayout background color.

Ilya Gazman
  • 31,250
  • 24
  • 137
  • 216
  • That is exactly what I tried, except the `RelativeLayout` will fit inside the `CardView` but won't expand inside it. As a result I don't get my desired rounded corners. – Greg Peckory Feb 14 '16 at 14:07
  • 2
    @GregPeckory You can use a drawable shape to get rounded corners. Any way you should try more tower this direction, it should work. – Ilya Gazman Feb 14 '16 at 14:08
0

As a workaround, since the alpha is the problem, you can try to brigthen the card color (or blend it with the underlying color)

ColorUtils.blendARGB(yourCardColor, Color.WHITE, 0.2f)
Ingrid
  • 1
-3

Instead of that, set android:background="#hexColor"

Nick Isaacs
  • 172
  • 11