1

My goal is to create a simple CardView with white background AND having a ripple effect when clicking on it. By just enabling the ripple effect with:

android:clickable="true"
android:foreground="?android:attr/selectableItemBackground"

The ripple is shown. But at this point, the background is a dark grey. So let's change it to white

card_view:cardBackgroundColor="#FFFFFF"

Now my CardView is white, but there is no ripple anymore. No matter what I try, either I get only ripple, or only white background.

Hope you can help me! Thanks

maximilian
  • 35
  • 7

1 Answers1

0

check it out for details Material effect on button with background color

create a xml drawable and use as your background (API 21+).

  <?xml version="1.0" encoding="utf-8"?>
    <ripple xmlns:android="http://schemas.android.com/apk/res/android"
            android:color="?attr/colorControlHighlight">
        <item android:drawable="?attr/colorPrimary"/>
    </ripple>
Community
  • 1
  • 1
ugur
  • 3,604
  • 3
  • 26
  • 57
  • Thanks. I created a xml drawable and placed it in the drawable folder. But AndroidStudio won't let me choose this as card_view:cardBackgroundColor="@color/...". Any ideas? – maximilian Mar 22 '16 at 19:58
  • set your background with this attr: android:foreground = //ripple bacground sample usage: http://stackoverflow.com/a/30046813/5923606 – ugur Mar 22 '16 at 20:20
  • Works perfectly. Thanks mate! – maximilian Mar 22 '16 at 21:12