I have written code for a custom ListView. It is just a view with three te开发者_如何学运维xtfields. I have used setBackgroundColor to set the row background to white. However, when I click on a row, the color no longer changes. I am doing this entirely programmatically. Is there a method to get back the Android selector color on clicking a ListView row?
The changing selection colour is a property of the background drawable belonging to the list item. You will have to specify one yourself, using a state list drawable.
More info here:
Drawable Resources: State List
And here:
What is the default drawable for pressing a list item
Annoyingly, the system's default list item background is not accessible from apps, so you'll have to copy the original (or use your own style if you prefer).
精彩评论