Search code examples
androidlistviewdividerholoeverywhere

Listview dividers color with HoloEveryWhere


I'm using HoloEveryWhere to get support of the Holo themes on android 2.x and I want to change the default color of my ListView dividers.

I did this :

<ListView
        android:id="@+id/listRecherche"
        android:layout_marginLeft="15dp"
        android:layout_marginRight="15dp"
        android:layout_width="wrap_content"
        android:divider="#e5e5e5"
        android:dividerHeight="1dp"
        android:layout_height="wrap_content" >
</ListView>

It works well on android 4.x but in 2.x, what I get is no more dividers and instead a #e5e5e5 background on the whole ListView.

I've thought about a height problem since I know that changing the dividers color resets the dividers height. This is why I've set heights at the end... but no effect.


Solution

  • Use a drawable instead of an RGB color Just put a file named divider.xml in res/drawable/ so you can access it as R.drawable.divider; if you can access it that way, then you can use android:divider="@drawable/divider" in the XML for ListView.

    <?xml version="1.0" encoding="UTF-8"?> 
      <shape xmlns:android="schemas.android.com/apk/res/android"> 
        <gradient 
           android:startColor="#ffcdcdcd" 
           android:endColor="#ffcdcdcd" 
           android:angle="270.0" />
    

    And in styles.xml for listview item

    <item name="android:divider">@drawable/divider</item> 
    <item name="android:dividerHeight">1px</item>