- Get link
- X
- Other Apps
Ripple Effect in android Cardview
An Android developer must have to use Cardview, But with the cardview you must have to use a ripple effect for the better user experience. CardView is one of the most useful widget of android design pattern.
So Here is an example to add ripple effect into your cardview.
To implement cardview you need to implement the dependency which is:
1 | implementation "androidx.cardview:cardview:1.0.0"
|
Below code is the xml layout for your cardview
1 2 3 4 5 6 7 8 9 10 | <androidx.cardview.widget.CardView android:layout_width="match_parent" android:layout_height="150dp" app:cardElevation="5dp" android:layout_margin="10dp" android:foreground="?android:selectableItemBackground" // Step 1 is to set selectableItemBackground android:clickable="true" // Step 2 is to make clickable your cardview android:onClick="openAppActivity" > </androidx.cardview.widget.CardView> |
To make ripple effect in your cardview just add two lines
android:foreground="?android:selectableItemBackground"
android:clickable="true"
Happy Coding!
Thanks.
Comments
Post a Comment