How can I change background color of ListView
items on a per-item basis. When I use android:backgroundColor
in the ListView
item layout I can achieve this, however the list selector is no longer visible. I can make the selector visible again by setting drawSelectorOnTop
to true but then the selector overlays the whole item.
Any ideas how to change those background colors and keep the selector?
PS I would rather not change the selector itself.
EDIT: Authors of GMail application have managed to achieve exactly this so it's definitely possible.
Take a look at List14 example. In
getView()
you can callconvertView.setBackgroundDrawable()
for each entry. You could have a class member counter to decide which background to call it with to get alternating backgrounds, for example.Simple code to change all in layout of item (custom listview extends baseadapter):
In the list view you can add android:listselector=color name that you want.
this work fine in my app.
By changing a code of Francisco Cabezas, I got the following:
the easiest way is this. Inside your ListArrayAdapter just do this
don't over complicate
Following way very slowly in the running
Replaced by the following