安卓笔记-selector选择器

来源:互联网 发布:口袋妖怪pc网络 编辑:程序博客网 时间:2024/05/28 15:13
</pre><pre name="code" class="html"><span style="white-space:pre"></span><?xml version="1.0" encoding="utf-8" ?>   <selector xmlns:android="http://schemas.android.com/apk/res/android"> <!-- 默认时的背景图片-->    <item android:drawable="@drawable/pic1" />    <!-- 没有焦点时的背景图片 -->    <item android:state_window_focused="false"           android:drawable="@drawable/pic1" />   <!-- 非触摸模式下获得焦点并单击时的背景图片 -->    <item android:state_focused="true" android:state_pressed="true"   android:drawable= "@drawable/pic2" /> <!-- 触摸模式下单击时的背景图片-->  <item android:state_focused="false" android:state_pressed="true"   android:drawable="@drawable/pic3" />  <!--选中时的图片背景-->    <item android:state_selected="true"   android:drawable="@drawable/pic4" />   <!--获得焦点时的图片背景-->    <item android:state_focused="true"   android:drawable="@drawable/pic5" />   </selector>



    xml文件: android:listSelector="@drawable/mylist_view"
    android:background="@drawable/mylist_view"
    Java代码:     Drawable drawable = getResources().getDrawable(R.drawable.mylist_view);   
                                listView.setSelector(drawable);


android:state_active    代表是否处于激活状态
    android:state_checked     代表是否处于已勾选状态
    android:state_checkable                  代表是否处于可勾选状态         
    android:state_enabled       代表是否处于可用状态
    android:state_first    代表是否处于开始状态
    android:state_focused    代表是否已得到焦点状态
    android:state_last    代表是否处于结束状态
    android:state_middle    代表是否处于中间状态
    android:state_pressed    代表是否处于被按下状态
    android:state_selected     代表是否处于被选中状态
    android:state_window_focused    代表是否窗口已得到焦点状态 



  


0 0
原创粉丝点击