RecyclerView + CardView +触摸反馈 [英] RecyclerView + CardView + Touch feedback

查看:193
本文介绍了RecyclerView + CardView +触摸反馈的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

RecyclerView 内是否有人解决了 CardView 的秘密而没有触摸反馈的问题?

Has anybody solved the mystery of the CardView without touch feedback when it's inside a RecyclerView?

我有一个带有一堆CardViews(一个 CardList )的RecyclerView.当我单击任何CardView时,我将启动另一个活动.一切正常,但是单击CardView时看不到任何触摸反馈.

I have a RecyclerView with a bunch of CardViews (a CardList). When I click on any CardView, I start another Activity. That's working pretty fine, but I can't see any touch feedback when I click on the CardView.

及时,我已经用以下配置了CardView(XML):

Just in time, I've already configured my CardView (XML) with these:

android:clickable="true"
android:background="?android:selectableItemBackground"

谢谢!

推荐答案

背景:

CardView忽略android:background,而只使用彩色的app:cardBackground.边框和阴影实际上是背景的一部分,因此您无法设置自己的边框.

The CardView ignores android:background in favor of app:cardBackground which can only be color. The border and shadow are in fact part of the background so you cannot set your own.

解决方案:

使CardView内的布局可单击,而不是卡本身.您已经写了此布局所需的两个属性:

Make the layout inside the CardView clickable instead of the card itself. You already wrote both attributes needed for this layout:

android:clickable="true"
android:background="?android:selectableItemBackground"

这篇关于RecyclerView + CardView +触摸反馈的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆