Ripple effect on Android Lollipop CardView
Master System Design with Codemia
Enhance your system design skills with over 120 practice problems, detailed solutions, and hands-on exercises.
Introduction
On Android 5.0 and later, the ripple effect is the standard touch feedback for Material-style components. With CardView, the main task is not enabling the ripple itself, but attaching it to the clickable surface in a way that still looks correct with elevation and rounded corners.
The Simplest XML Setup
If your CardView is the interactive element, make it clickable and assign a selectable foreground. Since CardView derives from FrameLayout, it can display a foreground drawable on Lollipop and later.
That gives you default Material ripple feedback without writing custom drawables.
Handling Clicks in Code
The ripple only shows when the view is actually interactive, so wire the click listener to the same view that owns the foreground.
If you put the click listener on a child view instead, the user may tap the card and see no ripple where they expect it.
Using a Custom Ripple Color
The default theme ripple is often enough, but you can define your own ripple drawable when design requires a custom color.
Then apply it as the foreground:
The mask is important when you want the ripple to visually respect rounded edges rather than appearing as a plain rectangle.
Why Some Card Ripples Look Wrong
CardView combines shadows, rounded corners, and content padding. That means a ripple can appear slightly misaligned or extend past the visually expected edge if the foreground is not masked carefully.
When that happens, two patterns help:
- Put the ripple on an inner container that matches the visible content area.
- Use a custom ripple mask with the same radius as the card.
For older support-library layouts, developers often wrapped content in a child FrameLayout and placed the foreground there because it gave more predictable clipping behavior.
A Practical Inner-Container Pattern
If the direct CardView foreground does not behave the way you want, move the ripple to the child content container:
This pattern is often easier to tune because the inner layout owns both the visible background and the interaction state.
Common Pitfalls
- Adding a ripple drawable without making the touched view clickable and focusable.
- Wiring the click listener to a child view while expecting the outer card to show the feedback correctly.
- Assuming the default ripple will always respect rounded corners without a custom mask.
- Ignoring padding and nested containers when the ripple looks offset or clipped oddly.
- Sticking with old
CardViewpatterns whenMaterialCardViewwould fit the current design system better.
Summary
- The easiest ripple setup is a clickable
CardViewwith a selectable foreground. - Attach the click listener to the same view that owns the ripple.
- Use a custom
rippledrawable and mask when rounded corners need precise clipping. - An inner clickable container can behave more predictably than the outer card.
- For newer apps,
MaterialCardViewis often a better long-term choice than plainCardView.

