Cardview Ripple Effect Doesn't Work
Min SDK is 21. When I click on a cardview in my recycler adapter, the ripple effect doesn't happen and just goes to the next screen. The recyclerview is inside a fragment.
Solution 1:
Your card view contains relative layout which covers the card view surface, so write ripple effect in relative layout.
<android.support.v7.widget.CardView
android:id="@+id/cardView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:cardPreventCornerOverlap="false"
app:cardElevation="2dp"
app:cardUseCompatPadding="false"
app:cardCornerRadius="2dp"
android:layout_marginBottom="8dp"
android:layout_marginRight="8dp"
android:layout_marginLeft="8dp"
>
<RelativeLayout
android:id="@+id/rl_bookmark"
android:background="?attr/selectableItemBackground"
android:clickable="true"
android:layout_width="match_parent"
android:layout_height="match_parent"> ...
Solution 2:
Solution 3:
Try wrapping your image in a FrameLayout
with a foreground attribute of:
android:foreground="?attr/selectableItemBackground"
E.g.
<FrameLayoutandroid:layout_width="match_parent"android:layout_height="wrap_content"android:clickable="true"android:focusable="true"android:foreground="?attr/selectableItemBackground"
><ImageViewandroid:id="@+id/pet_image"android:layout_width="match_parent"android:layout_height="210dp"android:layout_alignParentTop="true"android:scaleType="centerCrop"android:src="@drawable/placeholder"android:visibility="gone"
/></FrameLayout>
Solution 4:
Another way to solve this: Using a Button Style
Add the Borderless Button Style to the root element of your layout.
There's no need for focusable
or clickable
attributes, the default styling encapsulates all that for you.
<androidx.constraintlayout.widget.ConstraintLayoutstyle="@android:style/Widget.Material.Button.Borderless"android:layout_width="match_parent"android:layout_height="wrap_content">
NOTE: Add the style to the ViewGroup
in your CardView
that houses other views
Solution 5:
Just add background to your child view inside MaterialCardView.
android:background="?attr/selectableItemBackground"
<com.google.android.material.card.MaterialCardView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="4dp"
android:layout_marginBottom="4dp"
android:background="@color/white">
<androidx.constraintlayout.widget.ConstraintLayout
android:id="@+id/item_view"
android:layout_width="match_parent"
android:background="?attr/selectableItemBackground"
android:layout_height="wrap_content" >
// -> rest of your design
</androidx.constraintlayout.widget.ConstraintLayout>
</com.google.android.material.card.MaterialCardView
Post a Comment for "Cardview Ripple Effect Doesn't Work"