Question

How can I replace the color of a listview item background when in the non-(focused|pressed|activated) state with a custom color, but keep all the system default colors for pressed, long-pressed, activated, focused etc. states?

I'm trying to give my listviews a card style - that is white items with space in between on a grey background (as in Google Play Store app and others).

So I want to give the items a white background, but at the same time, keep all the system default selectors, including the fade animation for long press. That is, I want to replace the transparent color for the inactive states with white, but keep all the other states as by default.

This is even more important since the KitKat release, because all the accents have now switched from blue to grey, so I would like the app to respect that - to have blue color when pressed on ICS and JellyBean, but grey on KitKat. Therefore, I don't want to hard-code any values into a custom selector.

Was it helpful?

Solution

All right, I figured it out and it's incredibly simple:

All I have to do is to add this attribute to the given ListView:

android:drawSelectorOnTop="true"

And that's all! I can give the list items any background color that I want and it will always be overlayed by the system default selector!

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top