直播程序源码ListView选中时改变其背景图片

实现原理其实很简单,如下所示

<ListView
                android:id="@+id/lv_jiemu"
                android:layout_width="370px"
                android:layout_height="wrap_content"
                android:listSelector="@drawable/listview_selected" >
            </ListView>

ListView有一个listSelector属性,其大概意思是listview中的item选中时

然后在定义listview_selected.xml文件,如下所示

<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
 
    <!-- 没有焦点时的背景图片 -->
    <!-- <item android:state_window_focused="false"/> -->
    <!-- 非触摸模式下获得焦点并单击时的背景图片 -->
    <item android:drawable="@drawable/sfd" android:state_focused="true" android:state_pressed="true"/>
    <!-- 触摸模式下单击时的背景图片 -->
    <!--
   <item android:state_focused="false"
    android:state_pressed="true"  
    android:drawable="@drawable/pic3"/>
    -->
    <!-- 选中时的图片背景 -->
    <item android:drawable="@drawable/sfd" android:state_selected="true"/>
    <!-- 获得焦点时的图片背景 -->
    <item android:drawable="@drawable/sfd" android:state_focused="true"/>
 
</selector>
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章