我正在搜索如何在扩展/崩溃时更改groupview的背景。我没有找到答案,但我解决了这个问题:
BaseExpandableListAdapter:
@Override
public View getGroupView(int groupPosition, boolean isExpanded, View convertView, ViewGroup parent) {
ViewHolderGroup holder;
if ( convertView == null ){
convertView = inflater.inflate(R.layout.home_cell, null);
holder = new ViewHolderGroup();
convertView.setTag(holder);
holder.tvNome = (TextView) convertView.findViewById(R.id.cellNome);
holder.btCodigo = (ToggleButtonEbrimaBold) convertView.findViewById(R.id.btCodigo);
holder.tvLancadas = (TextView) convertView.findViewById(R.id.cellLancadas);
holder.layoutBackground = (LinearLayout) convertView.findViewById(R.id.layoutBackground);
}
else{
holder = (ViewHolderGroup) convertView.getTag();
}
holder.layoutBackground.setSelected(isExpanded);
return convertView;
}
ViewHolderGroup :
class ViewHolderGroup {
TextView tvNome;
ToggleButtonEbrimaBold btCodigo;
TextView tvLancadas;
LinearLayout layoutBackground;
LinearLayout layoutReceiver;
}
home_cell.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent">
<LinearLayout
android:id="@+id/layoutBackground"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:minHeight="100dp"
android:orientation="vertical"
android:gravity="center_vertical"
android:background="@drawable/disciplina_line">
... GroupView content ...
</LinearLayout>
</LinearLayout>
disciplina_line.xml:
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:state_selected="false" android:drawable="@drawable/line_white"/>
<item android:state_selected="true" android:drawable="@drawable/line_selected"/>
</selector>
我想分享这个选择。希望它有所帮助!