开发者

How do you get views to flash red when clicked?

开发者 https://www.devze.com 2023-03-28 03:04 出处:网络
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'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 Act开发者_高级运维ivity 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?


You could just add this to your main layout used for your items in your list :

android:addStatesFromChildren="true" android:background="@android:drawable/list_selector_background"

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

0

精彩评论

暂无评论...
验证码 换一张
取 消