繁体   English   中英

如何消除 MaterialCardVew 的波纹效应?

[英]How to remove ripple effect from MaterialCardVew?

如何禁用MaterialCardView的触摸波纹效果? clickable属性设置为false或使用foregroundbackground属性都没有效果。

我正在使用材料支持库版本1.1.0-alpha02

只有rippleColor是可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>

您还需要 clickable 和 focusable to false 以消除涟漪效应

<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>

只需在 xml 中使用此属性:
app:rippleColor="@android:color/transparent"

或者在 Kotlin 中以编程方式:
cardView.rippleColor = ColorStateList.valueOf(Color.TRANSPARENT)

你可以像这样使用 CSS:

.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;
    }
  }
}

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM