修改ExpandableListView中父Item的箭头图标

来源:互联网 发布:单片机电压测量电路 编辑:程序博客网 时间:2024/05/16 14:10

在Android系统中ExpandableListView的父Item项会有一个图标,用于指示当前是展开或闭合的状态.这个图标系统是有自带的. 自定父Item的layout时,并不能修改到它.要修改到它有个方法.  那就是自定义一个expandable_list_view_group_indicator.xml文件. 代码如下:

<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android" >
    <item android:state_expanded="true" android:drawable="@drawable/icon_expanded" />   
    <item android:drawable="@drawable/icon_up" />  
</selector>

在编写xml文件时, 在eclipse 中并不能自动弹出 android:state_expanded 这个属性值. 这点需要注意. 

然后在用到 ExpandableListView 的xml 文件中对它的 android:groupIndicator 进行设置, 代码如下:

..................................

<ExpandableListView
        android:id="@+id/expandabel_list_view"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        ........................................................
        android:groupIndicator="@drawable/expandable_list_group_indicator_icon" />


这样就可以显示自定义的图标.

当然也可以使用java代码的实现方式. 代码如下:

ExpandableListView  myExpandableListView;

myExpandableListView = (ExpandableListView)findById(R.id.expandabel_list_view);

myExpandableListView.setGroupIndicator(this.getResources().getDrawable(R.drawbale.expandable_list_group_indicator_icon)); 


0 0
原创粉丝点击