Android 如何通过布局xml文件更改ExpanableListView子分隔符的颜色?

Android 如何通过布局xml文件更改ExpanableListView子分隔符的颜色?,android,expandablelistview,Android,Expandablelistview,我想通过以下方式更改ExpandableListView的子分隔符的颜色: android:childDivider="@drawable/yellow" 在布局文件中。但是,当我折叠该项时,我发现ExpandableListView的背景变为黄色(@drawable/yellow),但我只想更改子分隔符的颜色。谁能告诉我为什么?令我惊讶的是,如果我用java代码修改它,比如 expandableListView.setChildDivider(this.getResources().get

我想通过以下方式更改
ExpandableListView
的子分隔符的颜色:

 android:childDivider="@drawable/yellow"
在布局文件中。但是,当我折叠该项时,我发现
ExpandableListView
的背景变为黄色(
@drawable/yellow
),但我只想更改子分隔符的颜色。谁能告诉我为什么?令我惊讶的是,如果我用java代码修改它,比如

expandableListView.setChildDivider(this.getResources().getDrawable(R.drawable.yellow));
它工作正常。很奇怪,谁能告诉我原因

<!-- 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"
    />

您只需从布局中删除
android:divider=“@drawable/yellow”
。如果我理解正确,这应该可以解决你的问题

我的意思是:

创建一个小高度的可绘制表格,并将其设置为ChildDifferent 财产

“child_separator.xml”:


只需将子分隔符设置为您选择的颜色

<ExpandableListView
        android:id="@+id/list_shopping"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:childDivider="@color/LightGrey"
        android:dividerHeight="1dp" />


您看到的屏幕截图将非常有用。谢谢!然而,也许你误解了我。我的意思是,如果我写“android:childDivider=“@drawable/yellow”,ExpandListView的背景将变为全黄色(在你的图像中仍然像往常一样是黑色)。我只是使用了你的代码,并试图猜出什么是错的。请添加你看到的问题的屏幕截图。然后将其上传到某个地方,并给我链接。
android:childDivider="@drawable/child_separator"
<ExpandableListView
        android:id="@+id/list_shopping"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:childDivider="@color/LightGrey"
        android:dividerHeight="1dp" />