改变TextView的背景涟漪 [英] Change TextView background with ripples
问题描述
我有一个RecyclerView(网格布局)的元素是TextViews。当用户点击一个TextView我改变背景颜色。我允许多项选择。所有这一切工作正常。现在我有一个新的规定,以显示纹波,当用户点击一个TextView。所以基本上我必须做到两件事:
I have a RecyclerView (grid layout) whose elements are TextViews. When a user clicks on a TextView I change the color of the background. I allow for multiple selections. All of this works fine. Now I have a new requirement to show ripple when a user clicks on a TextView. So basically I must accomplish two things:
- 显示纹波
- 改变的TextView 的背景
我如何做到这一点?我试着用的android:drawSelectorOnTop =真正的
在RecyclerView(XML),但并没有区别
How do I accomplish this? I tried using android:drawSelectorOnTop="true"
in the RecyclerView (xml) but that made no difference.
所以,想象一下我必须要改变蓝色和绿色之间的TextView的背景。但是,在上面我必须总是显示为纹波 onLongClick
So imagine I have to change the background of the TextView between blue and green. But on top I have to always show the ripple for the onLongClick
推荐答案
假设你使用的是Android的支持库修改的android:您的项目布局的背景
到?ATTR / selectableItemBackground
或?ATTR / selectableItemBackgroundBorderless
将适用于棒棒堂+设备上的纹波和退回到一个完整的项目选择低设备。
Assuming you are using the Android Support library change the android:background
of your item layout to ?attr/selectableItemBackground
or ?attr/selectableItemBackgroundBorderless
which will apply the ripple on Lollipop+ devices and fallback to a full item select on lower devices.
这篇关于改变TextView的背景涟漪的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!