方式一:在配置文件中有个android:groupIndicator属性,将其设置为:你的selector,例如:android:groupIndicator="@drawable/arrow_expandable_list"
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:drawable="@drawable/arrow_down_list_s" android:state_expanded="true"/>
<item android:drawable="@drawable/arrow_right_list_s"/>
</selector>
xml中设置groupIndicator属性设置箭头点击效果:
<ExpandableListView
android:id="@+id/exlist_video"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:groupIndicator="@drawable/arrow_expandable_list"
/>
方式二:
xml属性中设置为null:
<ExpandableListView
android:id="@+id/exlist_video"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:groupIndicator="@null"
/>
适配器中设置:
//取得用于显示给定分组的视图. 这个方法仅返回分组的视图对象
@Override
public View getGroupView(int groupPosition, boolean isExpanded, View convertView, ViewGroup parent) {
ViewHolderGroup groupHolder;
if(convertView == null){
convertView = LayoutInflater.from(mContext).inflate(
R.layout.item_exlist_group, parent, false);
groupHolder = new ViewHolderGroup();
groupHolder.tv_group_name = (TextView) convertView.findViewById(R.id.tv_group_name);
convertView.setTag(groupHolder);
}else{
groupHolder = (ViewHolderGroup) convertView.getTag();
}
/******************添加两星号行部分内容,动态设置箭头点击效果**********************/
if (iData.get(groupPosition).size() > 1){
if (isExpanded){
groupHolder.tv_group_name.setCompoundDrawablesWithIntrinsicBounds(parent.getContext().getResources().getDrawable(R.drawable.arrow_down_list),null,null,null);
} else {
groupHolder.tv_group_name.setCompoundDrawablesWithIntrinsicBounds(parent.getContext().getResources().getDrawable(R.drawable.arrow_right_list),null,null,null);
}
} else {
groupHolder.tv_group_name.setCompoundDrawablesWithIntrinsicBounds(null,null,null,null);
}
/**********************************************************************/
groupHolder.tv_group_name.setText(gData.get(groupPosition).getgName());
return convertView;
}
效果:方式一会出现变形和箭头大小不好控制的问题,方式二不存在这个问题,推荐使用方式二。
方式二效果: