Set color of 'empty' area of ListView in A

2020-08-26 04:08发布

问题:

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.

回答1:

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.



回答2:

Programatic solution accounting for the MotoBlur bug:

if (Build.VERSION.SDK_INT >= 8 && Build.VERSION.SDK_INT <= 10) {
   mListView.setOverscrollFooter(null);
}


回答3:

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.



回答4:

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