因为expandablelistview的默认箭头样式可能会跟我们自己的app风格不一致,需重新设置。
expandablelistview取消默认箭头有两种方法:
1.在布局文件xml中添加groupIndicator属性为@null
android:groupIndicator="@null"
2.在代码中设置:
mExLv.setGroupIndicator(null);
然后就是添加自己的箭头,当然就是使用selector,如果设置expandablelistview的groupindicator属性为指定的selector:
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:drawable="@mipmap/icon_group_selected" android:state_expanded="true" />
<item android:drawable="@mipmap/icon_group_normal" />
</selector>
则图片的scale type不好控制,会出现图片拉伸,暂时还不知道这种的解决办法。
所以我会在group view的item里面设置selector,scale type和位置等都可以很好的控制:
selector:
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:drawable="@mipmap/icon_group_selected" android:state_selected="true" />
<item android:drawable="@mipmap/icon_group_normal" />
</selector>
item布局:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center_vertical"
android:padding="10dp">
<TextView
android:id="@+id/tv"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:drawablePadding="5dp"
android:text="listview" />
</LinearLayout>
@Override
public View getGroupView(int groupPosition, boolean isExpanded, View convertView, ViewGroup parent) {
Holder holder = null;
if (convertView == null) {
holder = new Holder();
convertView = mInflater.inflate(R.layout.item_exlv_group, parent, false);
holder.tv = (TextView) convertView.findViewById(R.id.tv);
convertView.setTag(holder);
} else {
holder = (Holder) convertView.getTag();
}
holder.tv.setText(mGroupData.get(groupPosition));
holder.tv.setSelected(<span style="font-family:Arial, Helvetica, sans-serif;">isExpanded</span>);
return convertView;
}