Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

No ripples for MaterialCardView

Tags:

Are there no ripples on the new MaterialCardView?

I used CardView with android:clickable="true" and android:foreground="?android:attr/selectableItemBackground" which worked fine but with the new MaterialCardView there are no ripples at all 😰.

Other Views etc. keep working but I want my card to be clickable (with ripple as feedback).

like image 323
hardysim Avatar asked Jun 04 '18 08:06

hardysim


People also ask

How do I add ripple effect to CardView?

Adding Ripple Effect To enable this behavior, add the following attributes to your CardView . Using the android:foreground="? android:attr/selectableItemBackground" property on a CardView enables the ripple effect to originate from the touch origin.

What is MaterialCardView in android?

MaterialCardView is a customizable component based on CardView from the Android Support Library. MaterialCardView provides all of the features of CardView , but adds attributes for customizing the stroke and uses an updated Material style by default.


1 Answers

This is a bug with MaterialCardView. It's overriding the foreground after it's created. I've filled a bug. It should be fixed to show a ripple if the card is clickable without needing to set the foreground.

If you can't wait for a fix you could use CardView from the support lib, or you could change your code to set the foreground drawable after the CardView has been inflated, or we would gladly accept a pull request! Relevant code at: https://github.com/material-components/material-components-android/blob/master/lib/java/com/google/android/material/card/MaterialCardView.java. It can probably use https://github.com/material-components/material-components-android/blob/master/lib/java/com/google/android/material/ripple/RippleUtils.java and a RippleDrawable for SDK >= 21.

like image 125
Cameron Ketcham Avatar answered Oct 05 '22 03:10

Cameron Ketcham