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

Dal*_*len 11 android expandablelistview

我想ExpandableListView通过写改变子分隔符的颜色:

 android:childDivider="@drawable/yellow"
Run Code Online (Sandbox Code Playgroud)

在布局文件中.但是,当我折叠项目时,我发现ExpandableListView转弯黄色(@drawable/yellow)的背景,但我只是想改变子分隔符的颜色.谁能告诉我为什么?令我惊讶的是,如果我通过java代码更改它

expandableListView.setChildDivider(this.getResources().getDrawable(R.drawable.yellow));
Run Code Online (Sandbox Code Playgroud)

它正常工作.这很奇怪,谁能告诉我原因?

<!-- 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"
    />
Run Code Online (Sandbox Code Playgroud)

小智 23

创建一个小高度的drawable并将其设置为childDivider属性

"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>
Run Code Online (Sandbox Code Playgroud)

可扩展列表视图:

android:childDivider="@drawable/child_separator"
Run Code Online (Sandbox Code Playgroud)