android - CardView 点击状态不工作

标签 android material-design android-cardview

<分区>

我想在用户点击任何项目时更改卡片项目的颜色,但没有任何反应..为什么?

<android.support.v7.widget.CardView
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    card_view:cardCornerRadius="3dp"
    android:layout_marginTop="9dp"
    android:layout_marginLeft="9dp"
    android:layout_marginRight="9dp"
    card_view:cardElevation="0.01dp"
    android:layout_marginBottom="0dp"
    android:foreground="@drawable/card_foreground">

最佳答案

请试试这个..

添加 android:clickable="true"android:focusable="true" 和 将 android:foreground 更改为 android:foreground="?android:selectableItemBackground"

<android.support.v7.widget.CardView
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    card_view:cardCornerRadius="3dp"
    android:layout_marginTop="9dp"
    android:layout_marginLeft="9dp"
    android:layout_marginRight="9dp"
    card_view:cardElevation="0.01dp"
    android:layout_marginBottom="0dp"
    android:clickable="true"
    android:focusable="true"
    android:foreground="?android:selectableItemBackground" >

</android.support.v7.widget.CardView>

关于android - CardView 点击状态不工作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30450330/

相关文章:

android - AppCompat、Vectors 和 4.1.2 发生奇怪的崩溃

android - 滚动时禁用/暂停 RecyclerView 动画和/或只允许 RecyclerView 动画

android - 授权净付款

android - RecyclerView 适配器显示空白卡片 View

android - 简单的 Android 加减法应用程序

java - 为什么 FAB 在不同的 Android 设备/操作系统版本上显示不同?

android - 如何在 Android Studio 中创建我的代码格式样式?

java - Android 滑动选项卡崩溃 ( logcat : Can't convert to color: type=0x1 )

android - 在 Lollipop 之前的 CardView 下方的 float 操作按钮

Android:如何在设置可绘制背景时保持角半径?