【问题标题】:How to remove ripple effect from MaterialCardVew?如何从 MaterialCardView 中移除涟漪效应?
【发布时间】:2019-06-05 18:49:23
【问题描述】:

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

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

【问题讨论】:

标签: java android android-layout material-design materialcardview


【解决方案1】:

只有rippleColorstyleable

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

【讨论】:

  • 在 MaterialCardView 中没有 rippleColor 属性。那么你是如何删除它的呢?你能解释一下吗?
  • @vikassingh 有。也许你的依赖是旧的?试试 1.1.0-beta07
【解决方案2】:

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

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

【讨论】:

    【解决方案3】:

    你可以像这样使用 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;
        }
      }
    }
    

    【讨论】:

    • 这个问题是关于android的
    猜你喜欢
    • 2018-11-13
    • 2020-03-10
    • 2021-03-18
    • 1970-01-01
    • 2021-12-03
    • 2016-04-25
    • 1970-01-01
    • 2018-02-23
    • 2021-10-15
    相关资源
    最近更新 更多