AnimatedExpandableListView 项目不可选择
AnimatedExpandableListView items not selectable
我有一个 AnimatedExpandableListView,其项目在用户单击时展开和折叠。 我希望所选项目在展开时突出显示,并在折叠时返回其原始状态(未突出显示)。
AnimatedExpandableListView 的 xml:
<com.packagename.library.AnimatedExpandableListView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginTop="10dp"
android:divider="@null"
android:dividerHeight="0dp"
android:choiceMode="singleChoice"/>
AnimatedExpandableListView 项目的 LinearLayout,我想在选中时更改其背景:
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:background="@drawable/list_selector"/>
以及所选状态侦听器的可绘制背景:
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:drawable="@drawable/blue_linear_layout" android:color="@color/white" android:state_selected="true"/>
<item android:drawable="@drawable/blue_linear_layout" android:color="@color/white" android:state_activated="true"/>
<item android:drawable="@drawable/gray_linear_layout" />
</selector>
设置 choiceMode=singleChoice
并将 list_selector
可绘制对象添加到常规 ListView 项目的背景中工作正常,但它似乎不适用于 AnimatedExpandableListView。
Here 是我在项目中使用的 AnimatedExpandableListView class 的 github。
提前致谢!
在您的 Adapters getGroupView 方法中使用此代码
if (isExpanded){
convertView.setBackgroundColor(Color.BLACK);
}else {
convertView.setBackgroundColor(0);
}
我有一个 AnimatedExpandableListView,其项目在用户单击时展开和折叠。 我希望所选项目在展开时突出显示,并在折叠时返回其原始状态(未突出显示)。
AnimatedExpandableListView 的 xml:
<com.packagename.library.AnimatedExpandableListView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginTop="10dp"
android:divider="@null"
android:dividerHeight="0dp"
android:choiceMode="singleChoice"/>
AnimatedExpandableListView 项目的 LinearLayout,我想在选中时更改其背景:
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:background="@drawable/list_selector"/>
以及所选状态侦听器的可绘制背景:
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:drawable="@drawable/blue_linear_layout" android:color="@color/white" android:state_selected="true"/>
<item android:drawable="@drawable/blue_linear_layout" android:color="@color/white" android:state_activated="true"/>
<item android:drawable="@drawable/gray_linear_layout" />
</selector>
设置 choiceMode=singleChoice
并将 list_selector
可绘制对象添加到常规 ListView 项目的背景中工作正常,但它似乎不适用于 AnimatedExpandableListView。
Here 是我在项目中使用的 AnimatedExpandableListView class 的 github。
提前致谢!
在您的 Adapters getGroupView 方法中使用此代码
if (isExpanded){
convertView.setBackgroundColor(Color.BLACK);
}else {
convertView.setBackgroundColor(0);
}