How to Change the color of child divider of ExpanableListView by layout xml file?
Asked Answered
A

3

11

I want to change the color of child divider of ExpandableListView by writing:

 android:childDivider="@drawable/yellow"

in layout file. However, when I collapse the item, I found the background of the ExpandableListView turn yellow (@drawable/yellow) , but I just want to change the color of child divider. Who can tell me why? To my surprise, if I change it by java code like

expandableListView.setChildDivider(this.getResources().getDrawable(R.drawable.yellow));

it works normally. It is very weird, who can tell me the reason?

<!-- if I set childDivider in Layout xml, it can't work normally. 
     However, if set childDivider in java code, it work normally -->

<ExpandableListView android:id="@+id/list"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:layout_alignParentLeft="true"
    android:dividerHeight="2dp"
    android:divider="@drawable/yellow"
    android:childDivider="@drawable/yellow"
    />
Anthology answered 1/6, 2011 at 6:5 Comment(1)
A screenshot of what you see would help greatly.Desolate
A
23

create a drawable with small height and set it to childDivider property

"child_separator.xml":

<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android" 
    android:shape="rectangle">
    <solid android:color="@color/child_separator_color"/>
    <size android:height="1dp"/>
</shape>

expandable list view:

android:childDivider="@drawable/child_separator"
Aurist answered 25/1, 2012 at 11:32 Comment(0)
T
3

Simply set child divider as the color of your choice.

<ExpandableListView
        android:id="@+id/list_shopping"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:childDivider="@color/LightGrey"
        android:dividerHeight="1dp" />
Touchandgo answered 11/5, 2015 at 7:2 Comment(1)
Not working for me. I don´t see any dividerSerotherapy
D
2

You just need to remove android:divider="@drawable/yellow" from your layout. This should resolve your problem if I understood it correctly.

Here is what I mean:

enter image description here

Desolate answered 1/6, 2011 at 6:48 Comment(3)
Thank you! however,maybe you missunderstand me. I means that if I write "android:childDivider="@drawable/yellow" the background of ExpandListView will become all yellow(in your image is still black as usual).Anthology
I just used your code and tried to guess what was wrong. Please add screenshot of what you see to the question.Desolate
Then upload it to some place and give me the link.Desolate

© 2022 - 2024 — McMap. All rights reserved.