1

In the image below is a gray area under my listview and above my button. I want that area to have the same background color (black) as the list.

What seems odd to me is that in the emulator it's black, but on my phone, it's this gray.

enter image description here

I've tried setting the background color of the layout, the list, and the cachecolorhint... no matter what, it stays gray.

Current layout:

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent" 
    android:background="#000000" >
    <TextView
        android:id="@+id/header"
        android:layout_width="fill_parent"
        android:layout_height="27dp"
        android:layout_alignParentTop="true"
        android:layout_gravity="center|center_vertical"
        android:gravity="center"
        android:textColor="#00ccff"
        android:textSize="20dp" />
     <TextView
        android:id="@+id/horizontalline"
        android:layout_width="match_parent"
        android:layout_height="2dip"
        android:layout_below="@id/header"
        android:background="#8b8b8b"
        android:paddingBottom="2dip"
        android:paddingTop="2dip" />
    <Button
        android:id="@+id/AddButton"
        android:layout_width="match_parent"
        android:layout_height="35dp"
        android:layout_alignParentBottom="true"
        android:layout_gravity="center"
        android:gravity="center|top"
        android:textSize="12dp" >
    </Button>
    <ListView
        android:id="@id/android:list"
        android:layout_width="match_parent"
        android:layout_height="0dp"
        android:layout_below="@id/horizontalline"
        android:background="#000000" 
        android:cacheColorHint="#000000" 
        android:layout_above="@id/AddButton"
        android:drawSelectorOnTop="false"
        android:listSelector="@android:color/transparent" />
    <TextView
        android:id="@android:id/empty"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_below="@id/header"
        android:gravity="center" />
</RelativeLayout>

Any help appreciated.

EDIT

To be clear, I have no problem with the list when it fills the screen, it's when there's only a few items that don't fill the screen I get this gray background... I would much prefer it be the same black background as the list.

1
  • give android:cacheColorHint="#000000" as #00000000. And what is the use of this TextView android:id="@android:id/empty"? May 18, 2012 at 15:39

4 Answers 4

8

Looking at your screenshot, it looks like your phone is a Motorola running 2.3+ (Droid 3?). I've seen the same "feature" on some Motorola phones.

Check this post on Motorola Blog for a complete answer. Basically, add on your ListView XML attributes android:overScrollFooter="#000000".

It only works for 2.3+ devices, so you'd rather put it in a style in res/values-v10/styles.xml:

<style name="MyListView" parent="@android:style/Widget.ListView">
    <item name="android:listSelector">@drawable/list_selector</item>
    <item name="android:overScrollFooter">#000000</item>
</style>

Then add this to your theme.xml:

<style name="MyTheme" parent="android:Theme">
    <item name="android:windowBackground">@null</item>
    <item name="android:listViewStyle">@style/MyListView</item>
</style>

Finally, apply your custom theme to your activity in your AndroidManifest:

<activity android:name="com.listtest.MainActivity"
    android:label="@string/app_name" 
    android:theme="@style/MyTheme">

I guess you can apply the style directly to the list, without passing by a theme, but this solution will work for all ListViews in your app as soon as you apply it to all your activities in the Manifest.

3
  • This looks promising, and it is exactly the issue I'm having. I'll give the solutions a try when I get home and accept your answer if they work. Thanks!
    – Barak
    May 19, 2012 at 14:58
  • That was indeed the issue. Much better looking lists now.
    – Barak
    May 19, 2012 at 17:17
  • 1
    Oh dear god, wow, this worked after hours of thrashing. I did not have to add a theme, just specify the footer color. Many thanks and up-votes! Apr 19, 2013 at 0:31
1

// this looks fine for me

    <?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent" 
    android:background="#000000" >
    <TextView
        android:id="@+id/header"
        android:layout_width="fill_parent"
        android:layout_height="27dp"
        android:layout_alignParentTop="true"
        android:layout_gravity="center|center_vertical"
        android:gravity="center"
        android:textColor="#00ccff"
        android:textSize="20dp" />
     <TextView
        android:id="@+id/horizontalline"
        android:layout_width="match_parent"
        android:layout_height="2dip"
        android:layout_below="@id/header"
        android:background="#8b8b8b"
        android:paddingBottom="2dip"
        android:paddingTop="2dip" />
    <TextView

        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_below="@id/header"
        android:gravity="center" 
        android:background="#000" 
        />
    <Button
        android:id="@+id/AddButton"
        android:layout_width="match_parent"
        android:layout_height="35dp"
        android:layout_alignParentBottom="true"
        android:layout_gravity="center"
        android:gravity="center|top"
        android:textSize="12dp" >
    </Button>
    <ListView
        android:id="@id/android:list"
        android:layout_width="match_parent"
        android:layout_height="0dp"
        android:layout_below="@id/horizontalline"
        android:background="#000000" 
        android:cacheColorHint="#000000" 
        android:layout_above="@id/AddButton"
        android:drawSelectorOnTop="false"
        android:listSelector="@android:color/transparent" />
</RelativeLayout>
3
  • I don;t have a problem with the list (per se)... it's the area under it when it doesn't fill the entire screen.
    – Barak
    May 18, 2012 at 15:52
  • my last try can you remove the id android:id="@android:id/empty". May 18, 2012 at 16:05
  • Tried it, same result. :( I emptied the list, so the empty TextView came into play and the whole screen was black. Add an item to the list and the gray screen under the list was back again. It's got to be something to do with the listview.
    – Barak
    May 19, 2012 at 3:45
0

Well, it doesn't look like the list is expanding the remaining space? Is that intended?

Also, to change the grey, wouldn't you need to set the background colour of the "empty" textview, since it appears to be spanning the entire height, I'm guess that's the textview that appears grey.

1
  • Nope. Just tried to set the background of that textview to black, same gray underneath the list.
    – Barak
    May 18, 2012 at 15:51
0

Try this (I'm not sure if this solves your problem...):

<ListView
    android:id="@+id/my_list"
    android:layout_width="match_parent"
    android:layout_height="fill_parent"
    android:layout_below="@id/horizontalline"
    android:background="#000000" 
    android:cacheColorHint="#000000" 
    android:layout_above="@id/AddButton"
    android:drawSelectorOnTop="false"
    android:listSelector="@android:color/transparent" />

(The height of a listview should be always fill_parent)

1
  • Nope, still get the gray area under the listview when it doesn't fill the screen.
    – Barak
    May 18, 2012 at 15:57

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.