selector无法改变tablehost中的图片

失败实例:

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

    <item android:drawable="@drawable/icon_selfinfo_nor"/>

</selector>

 

成功实例:

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

    <item android:drawable="@drawable/icon_selfinfo_nor"/>

</selector>

上面实现了通过单击而改变图片状态

 

selector属性:

<selector>
        必须。必须是根元素。包含一个或多个<item>元素。
         Attributes

            xmlns:android

                  String,必须。定义XML的命名空间,必须是
                   “http://schemas.android.com/apk/res/android”.

   <item>

          android:state_pressed
               Boolean“true”表示按下状态使用(例如按钮按下);“false”
               表示非按下状态使用。
           android:state_focused

               Boolean“true”表示聚焦状态使用(例如使用滚动球/D-pad
               聚焦Button);“false”表示非聚焦状态使用。
           android:state_selected

               Boolean“true”表示选中状态使用(例如Tab 打开);“false”
               表示非选中状态使用。
           android:state_checkable

               Boolean“true”表示可勾选状态时使用;“false”表示非可
              
勾选状态使用。(只对能切换可勾选非可勾选的构件有用。)
           android:state_checked

                 Boolean“true”表示勾选状态使用;“false”表示非勾选
状态使用。
           android:state_enabled

               Boolean“true”表示可用状态使用(能接收触摸/点击事件);
               “false”
表示不可用状态使用。
           android:window_focused

              Boolean“true”表示应用程序窗口有焦点时使用(应用程序
             
在前台);“false”表示无焦点时使用(例如Notification栏拉
             
下或对话框显示)。

     注意:记住一点,StateList中第一个匹配当前状态的item会被使用。因此,如果第一个item

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值