-3

I try to set the color of my ListView Divider lines, but when I do this they just disappear:

    <ListView
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:divider="@color/white"
        android:id="@+id/lvSomeListView"/>

I posted this question because even though there are similar questions which IMPLICITLY contain the answer, none of them are worded in such a way to make this answer obvious. I spent hours trying to figure this out, so I tried to do a good thing and post question-answer to help anyone else in my situation.

vaultah
  • 44,105
  • 12
  • 114
  • 143
Siavash
  • 7,583
  • 13
  • 49
  • 69
  • don't take me wrong, but what about, http://stackoverflow.com/a/11254409/501696? – Blackbelt Apr 10 '15 at 09:52
  • @Blackbelt I appreciate your feedback. When I was having this issue, I was under the impression that I knew "how to change the divider color" (key word how), so I was ignoring any questions titled "HOW to ..." and instead was looking for a post from someone having issues changing the color. The question I have posted here aims to help someone else with this issue find the answer faster by wording the question so that a google search lands here. – Siavash Apr 12 '15 at 04:18

2 Answers2

0

Since the divider expects a drawable, setting the divider to a color will require that a dividerHeight be specified as well:

    <ListView
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:divider="@color/white"
        android:dividerHeight="1px"
        android:id="@+id/lvSomeListView"/>
Siavash
  • 7,583
  • 13
  • 49
  • 69
  • Did you answer this after @AndroidWeblineindia? Please mark a correct answer. – Jared Burrows Apr 12 '15 at 04:07
  • @JaredBurrows I entered this as a question-answer combo, my goal was to share my experience. I have to wait 2 days before accepting an answer. Also I meant to put px, vs dp. dp Causes problems in this case. – Siavash Apr 12 '15 at 04:10
  • What is a "question-answer" combo? It is advised **not** to use `px` and to use `dp`. – Jared Burrows Apr 12 '15 at 04:13
  • When you post a question, there is a check box for "answer you own question". It's meant for someone to post a question they have already found an answer to and just wanna share it to help others with same question. read this post regarding px http://stackoverflow.com/questions/3979218/android-listview-divider – Siavash Apr 12 '15 at 04:20
  • Please Google "android px vs dp", read this: http://stackoverflow.com/a/2025541/950427. – Jared Burrows Apr 12 '15 at 04:23
  • I am aware of the difference and I have read that article long when I started developing for android. did you read the post I referenced? I want my dividers to be 1 pixel on all devices. – Siavash Apr 12 '15 at 04:47
0

Applying only divider property doesn't work, you need to add android:dividerHeight property as well,change your code by below code:

<ListView
        android:id="@+id/lvSomeListView"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:divider="@color/white"
        android:dividerHeight="2dip" >
    </ListView>

dividerHeight can be in dip or px as well!!