Android ListView Default Divider Styles / Attributes
Asked Answered
H

2

21

I have a LinearLayout view that I am trying to add a divider to so that it looks exactly the same as the default ListView control. I am trying to replicate the edit contact within the default Android (Nexus S 2.3.3) Contacts app and I believe a LinearLayout would be best for performance.

I am using the code to replicate the divider as shown below:

    <View
    android:id="@+id/Separator"
    android:layout_width="fill_parent"
    android:layout_height="?android:attr/dividerHeight"
    android:background="?android:attr/divider"/>

How can I access the default divider color or drawable and also the divider height? I would like this to match the ListViews I have setup, so using the Android system attributes would be best I think. The above code crashes as shown below so I assume I can't access those attributes or am going about this incorrectly.

03-13 22:59:38.851: ERROR/AndroidRuntime(3575): Caused by: java.lang.RuntimeException: Binary XML file line #26: You must supply a layout_height attribute.
Hussar answered 13/3, 2011 at 13:6 Comment(0)
H
38

This is how it's done in Android source code

<View android:id="@+id/Separator"
  android:layout_width="match_parent"
  android:layout_height="wrap_content"
  android:background="?android:attr/listDivider" />
Haihaida answered 13/3, 2011 at 14:19 Comment(3)
how to get all this default values of android as you have mentioned in above answer i.e.?android:attr/listDivider ?Cotterell
I have the same question as Hunt: where did you get that value exactly?Zoubek
Is this same for ListView ?Preliminary
L
0

The source of Magician Knowledge must be https://developer.android.com/reference/android/R.attr.html

public static final int listDivider:

The drawable for the list divider. Must be a reference to another resource, in the form "@[+][package:]type:name" or to a theme attribute in the form "?[package:][type:]name".

So all I have to do type in that site search bar - "drawable for the list divider" or just "divider"

Liegnitz answered 20/9, 2013 at 18:48 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.