fer*_*hur 1 android expandablelistview android-selector
我有一个ExpandableListView.当孩子被扩大时,应该被视为"被选中".选择孩子时,孩子和孩子的孩子都应该显示不同的背景(向用户显示当前所选项目).
现在这就是我所拥有的:
XML
<ExpandableListView
android:id="@+id/listViewAccepted"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:choiceMode="singleChoice"
android:listSelector="@drawable/custom_selector" >
</ExpandableListView>
Run Code Online (Sandbox Code Playgroud)
ListView
setOnGroupClickListener(new OnGroupClickListener() {
@Override
public boolean onGroupClick(ExpandableListView parent, View view,int groupPosition, long id) {
view.setSelected(true);
parent.setItemChecked(groupPosition, true);
return false;
}
});
Run Code Online (Sandbox Code Playgroud)
选择器
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:state_pressed="true">
<shape>
<solid android:color="@color/holo_blue_light" />
</shape>
</item>
<item android:state_selected="true">
<shape>
<solid android:color="@color/green" />
</shape>
</item>
<item android:state_checked="true">
<shape>
<solid android:color="@color/green" />
</shape>
</item>
<item android:state_focused="true">
<shape>
<solid android:color="@color/green" />
</shape>
</item>
<item android:state_activated="true">
<shape>
<solid android:color="@color/green" />
</shape>
</item>
<item>
<shape>
<solid android:color="@color/transparent" />
</shape>
</item>
</selector>
Run Code Online (Sandbox Code Playgroud)
这是我如何做到的,以下更改了组视图.重写的方法包含在我的自定义ExpandableListAdapter中.
@Override
public View getGroupView(int groupPosition, boolean isExpanded,
View view, ViewGroup parent)
{
LinearLayout bevGroup = (LinearLayout) view.findViewById(R.id.myid);
if(isExpanded)
{
bevGroup.setBackgroundColor(context.getResources().getColor(R.color.bgGroupBlack));
}
else
{
bevGroup.setBackgroundColor(context.getResources().getColor(R.color.bgTransparent));
}
}
Run Code Online (Sandbox Code Playgroud)
孩子,只有在展开时才能看到,总是它应该是的颜色.
| 归档时间: |
|
| 查看次数: |
4044 次 |
| 最近记录: |