我想通过以下方式更改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"
/>
最佳答案
创建一个小高度的可拉伸的,并将其设置为childdivider
财产
“子分隔符.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>
可扩展列表视图:
android:childDivider="@drawable/child_separator"