Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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"
    />
like image 893
Dalen Avatar asked Jun 01 '11 06:06

Dalen


1 Answers

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"
like image 162
Iustin Octav Avatar answered Oct 07 '22 15:10

Iustin Octav