How to remove ripple effect from MaterialCardVew?
Asked Answered
A

4

25

How can I disable touch ripple effect of MaterialCardView? Setting clickable attribute to false or playing with foreground and background attributes had no effect.

I'm using material support library version 1.1.0-alpha02.

Analogous answered 10/1, 2019 at 20:33 Comment(2)
Possible duplicate of No ripples for MaterialCardViewClincher
@MartinZeitler This question is opposite! I've asked how to remove the ripple effect.Analogous
C
43

Only the rippleColor is a styleable:

<com.google.android.material.card.MaterialCardView
    style="@style/Widget.MaterialComponents.CardView"
    app:rippleColor="@android:color/transparent"
    android:layout_width="match_parent"
    android:layout_height="wrap_content">

</com.google.android.material.card.MaterialCardView>

Note: It doesn't remove the ripple effect from <androidx.cardview.widget.CardView though.

Clincher answered 12/1, 2019 at 0:46 Comment(3)
In MaterialCardView there is no rippleColor attribute. So how are you remove it? can you please explain?Quail
@vikassingh there is. Maybe your dependency is old? try 1.1.0-beta07Mulholland
doesnt work on android 13Entirely
S
2

Just use this attribute in xml:
app:rippleColor="@android:color/transparent"

Or programatically in Kotlin:
cardView.rippleColor = ColorStateList.valueOf(Color.TRANSPARENT)

Sourpuss answered 28/10, 2021 at 12:43 Comment(0)
S
1

You also need clickable and focusable to false to remove the ripple effect

<com.google.android.material.card.MaterialCardView
        style="@style/Widget.MaterialComponents.CardView"
        app:rippleColor="@android:color/transparent"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:clickable="false"
        android:focusable="false">
</com.google.android.material.card.MaterialCardView>
Standice answered 9/6, 2023 at 7:24 Comment(0)
Z
-4

You can do just using CSS like that:

.mdc-card__primary-action.card__primary-action.mdc-ripple-upgraded {
  &:hover,
  &:focus,
  &:active {
    &.mdc-card__primary-action::before,
    &.mdc-card__primary-action::after {
      background-color: rgba(255, 255, 255, 0) !important;
      opacity: 0 !important;
    }
  }
}
Zonda answered 26/3, 2021 at 1:25 Comment(1)
This question is about androidQuaint

© 2022 - 2024 — McMap. All rights reserved.