Set color of 'empty' area of ListView in Android
Asked Answered
N

4

9

When my list view is not completely full of list view items (ex my list view is tall enough for 8 items, but I only have 2), the empty area shows up as gray on my Droid X. In the emulator the empty area shows up as black.

How do I set the 'empty' area to transparent?

I've tried setting the background color, cache hints, but those only seem the change the background color of the listview where it has items, not the empty area.

Natter answered 28/6, 2011 at 14:45 Comment(1)
Have you tried setting the listview height to fill_parent? Maybe setting the background color then will give the result you are looking forDeery
M
18

Motorola used to have a blog post up about this behavior, but their blog is no longer online -- the answer is that on Motoblur 2.3, they set a default overscroll footer, which is fixable by setting android:overScrollFooter="@null", but only for Android 2.3+.

Their recommended app-wide solution is to use a custom theme with a custom listViewStyle set only in the values-v10 folder with that property set.

Maccaboy answered 1/10, 2011 at 21:41 Comment(2)
The blog post link doesn't seem to link anywhere relevant to this specific problem anymore (maybe they deleted it?), but this info still worked wonders for me. For anyone instantiating their ListView programmatically, note the setOverscrollFooter() method you can call on it after API level 9. Its parameter should be null.Elli
Yup, looks like Motorola removed their developers blog and now redirect all the links to somewhere random rather than 404ing or returning the correct content. I'll remove the link.Maccaboy
A
2

Programatic solution accounting for the MotoBlur bug:

if (Build.VERSION.SDK_INT >= 8 && Build.VERSION.SDK_INT <= 10) {
   mListView.setOverscrollFooter(null);
}
Appearance answered 12/8, 2014 at 19:24 Comment(0)
N
1

Looks like removing layout_alignParentBottom="true" did the trick. So rather than changing the gray color, the list view is only large enough to draw the items required.

Natter answered 28/6, 2011 at 15:0 Comment(0)
L
0

Removing layout_alignParentBottom="true" and changing height="wrap_content" is not entirely enough. These solutions work if there are no other widgets at the bottom of the screen or otherwise below the ListView.

But, if there are other layout items below the ListView, then you must wrap the ListView in another layout, such as a LinearLayout, so that the container can take on the necessary height (fill_parent) while the ListView within can be permitted to shrink itself (wrap_content) such that the gray background below the ListView will not be displayed by the modified Motorola OS v2.3.3 footer behavior.

Here is an example: List View Footer Background on Android 2.3.3

Litotes answered 13/10, 2011 at 16:38 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.