如何让视图在点击时闪烁红色?
我注意到,在大多数 Android 应用程序中,当您单击几乎任何类型的视图时,视图的背景会在继续执行其应执行的操作之前短暂闪烁红色。
我不知道该怎么做。在某些情况下,它似乎是内置的,但并非总是如此。我的 Activity 中的 Button 对象在单击时都会闪烁红色,我无需执行任何操作即可实现此目的。但是,我的 ListView 中的项目却没有。 ListView 中的每一行都对应一个包含多个其他视图的 ViewGroup。我希望整行(ViewGroup)在单击时闪烁红色。
我还应该指出,从功能上来说,一切都工作正常。我点击我的列表项,它的响应就像我设计的那样。它只是不闪烁红色。有人知道我错过了什么吗?
I've noticed that in most stock Android apps when you click on a View of pretty much any sort, the background of the View briefly flashes red before proceeding with whatever it's supposed to do.
I can't figure out how to do this. In some cases it seems to be built in, but not always. The Button objects I have in my Activity all flash red when clicked and I didn't have to do anything to make that happen. However, the items in my ListView do not. Each row in my ListView corresponds to a ViewGroup containing multiple other views. I want the whole row (ViewGroup) to flash red when it's clicked.
I should also point out that, functionally, everything is working properly. I click on my list item and it responds just as I designed it. It just doesn't flash red. Anyone know what I'm missing?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您可以将其添加到用于列表中项目的主布局中:
当选择一个子项时,所有父项(即您的布局/您所说的整行)都将被选中,对于按下的其他状态也是如此并且选择器将应用一个短转换。
顺便说一句,红色取决于供应商,在我的爱可视上,它是一个很好的橙色。
问候,
史蒂芬
You could just add this to your main layout used for your items in your list :
When one child is selected then all the parent (i.e your layout / the whole row as you said) will get selected, same for other states as pressed, etc. And the selector will apply a short transistion.
Btw, red is vendor dependent, on my Archos, it's a nice orange.
Regards,
Stéphane