如何在可扩展列表视图中将子分隔线设置为默认主题颜色
How to set the child divider to the default theme color in expandable list view
我想将子分隔线颜色设置为默认主题颜色。
我已经使用
删除了子分隔线
expandableList.setChildIndicator(null);
expandableList.setGroupIndicator(null);
expandableList.setDividerHeight(2);
现在,我只希望最后一个子分隔线有分隔线,而且它也应该有默认的主题分隔线颜色。
所以,在group_child.xml中,我添加了如下视图:
<View
android:id="@+id/divider_child"
android:layout_width="match_parent"
android:layout_height="0.5dp"
android:background="#FF0000" /> <------ How can I change this color to the default theme divider color
是否可以设置视图 > android: 背景颜色为默认主题颜色?我该怎么做?
如果您使用的是AppCompat主题,那么您需要将颜色属性引用到背景中,如下所示
<View
android:id="@+id/divider_child"
android:layout_width="match_parent"
android:layout_height="0.5dp"
android:background="?attr/colorPrimary" />
在你的getChildView
方法中写条件如下
if (childPosition == getChildrenCount(groupPosition) - 1) {
convertView.findViewById(R.id.divider_child).setVisibility(View.VISIBLE);
} else {
convertView.findViewById(R.id.divider_child).setVisibility(View.GONE);
}
使用默认主题分隔线颜色
android:background="?android:attr/listDivider"/>
我想将子分隔线颜色设置为默认主题颜色。
我已经使用
删除了子分隔线 expandableList.setChildIndicator(null);
expandableList.setGroupIndicator(null);
expandableList.setDividerHeight(2);
现在,我只希望最后一个子分隔线有分隔线,而且它也应该有默认的主题分隔线颜色。
所以,在group_child.xml中,我添加了如下视图:
<View
android:id="@+id/divider_child"
android:layout_width="match_parent"
android:layout_height="0.5dp"
android:background="#FF0000" /> <------ How can I change this color to the default theme divider color
是否可以设置视图 > android: 背景颜色为默认主题颜色?我该怎么做?
如果您使用的是AppCompat主题,那么您需要将颜色属性引用到背景中,如下所示
<View
android:id="@+id/divider_child"
android:layout_width="match_parent"
android:layout_height="0.5dp"
android:background="?attr/colorPrimary" />
在你的getChildView
方法中写条件如下
if (childPosition == getChildrenCount(groupPosition) - 1) {
convertView.findViewById(R.id.divider_child).setVisibility(View.VISIBLE);
} else {
convertView.findViewById(R.id.divider_child).setVisibility(View.GONE);
}
使用默认主题分隔线颜色
android:background="?android:attr/listDivider"/>