自定义 selectableItemBackground

Jum*_*mpa 5 android android-styles android-recyclerview

我正在使用 RecyclerView 作为列表。我找到了一个非常好的解决方案来提供列表点击反馈和涟漪(在棒棒糖上)。基本上我给我的行布局属性:

android:background="?android:attr/selectableItemBackground"
Run Code Online (Sandbox Code Playgroud)

一切都很好,除了我的列表需要不同的背景颜色(默认状态)。如何仅覆盖基本状态背景(未单击)并为其赋予不同的颜色?

小智 8

这将提供自定义背景颜色和默认灰色波纹效果:

android:background="@color/YourCustomColor"
android:foreground="?android:attr/selectableItemBackground"
Run Code Online (Sandbox Code Playgroud)


All*_*OOP 0

CardViews在你的 中使用吗RecyclerView?如果是这样,请以编程方式.setCardBackgroundColor()在您的holderto every中使用CardView。或者,您可以将所有内容包装在 中的一个简单的虚拟对象FrameLayout(带有 android:id)中CardView,并在绑定ViewHolders.