我试图通过在活动XML文件中设置android:backgound属性(如android Developers页面上的here所述),让CardView在touch 时显示连锁react ,但它不起作用.完全没有动画,但是调用了onClick中的方法.我也try 过制造涟漪.xml文件,如建议的here,但结果相同.

在活动的XML文件中显示的CardView:

<android.support.v7.widget.CardView
    xmlns:card_view="http://schemas.android.com/apk/res-auto"
    android:layout_width="155dp"
    android:layout_height="230dp"
    android:elevation="4dp"
    android:translationZ="5dp"
    android:clickable="true"
    android:focusable="true"
    android:focusableInTouchMode="true"
    android:onClick="showNotices"
    android:background="?android:attr/selectableItemBackground"
    android:id="@+id/notices_card"
    card_view:cardCornerRadius="2dp">

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

我对安卓系统的开发还比较陌生,所以我可能犯了一些明显的错误.

推荐答案

您应该将以下内容添加到CardView:

android:foreground="?android:attr/selectableItemBackground"
android:clickable="true"

Android相关问答推荐

如何自定义所选的NavigationBar项目?

在Android Studio Iguana上运行示例代码时,Gradle Build错误

房间@嵌入式VS一对一关系

Android 中 recyclerview 的自定义分隔线 colored颜色 不起作用

当提供非状态对象时,compose 如何进行重组

Kotlin - 在继续之前如何等待这个协程完成?

kotlin中&&和and的区别

Android Studio Relay插件(版本0.3.07)错误

我如何比较多个时间范围并在 Android Compose 中并排显示它们

我的自定义小吃店不适合我的全宽屏幕尺寸

React Native Android 应用程序在调试模式下运行良好,但当我们发布 apk 时,它会生成旧版本的应用程序

如何在 React Native 中调试网络响应

当包含可绘制对象的整数变量传递给 painterResource 函数时,为什么图像不在 Android Studio 中呈现?

如何在 BottomBar jetpack compose 中删除选定的椭圆项目 colored颜色

如何在屏幕旋转或系统主题更改后将光标移动到 TextField 的末尾并保持键盘显示?

缺少类 com.google.android.datatransport.runtime.ForcedSender

在 Kotlin 中打开新片段时如何对当前片段应用更改?

在jetpack compose中将图像添加到脚手架顶部栏

如何在 Android 上移动 EditText 上的图标?

CenterAlignedTopAppBar 滚动行为:未为参数状态传递值