您的位置:首页 > 移动开发 > Android开发

android中CheckBox的高级应用之button属性

2012-12-24 08:42 344 查看
在我们普通的应用中checkBox里有多个Item时,页面中会自动为我们提供复选框的按钮,但我们有时会遇到这要的情况,CheckBox应用的对象不需要多个Item而是每个CheckBox对应平行的每一个选项,而且要求作出按钮(buuton)有CSS属性改变的效果,此时就必须要用到CheckBox的高级应用:以下是个人的一点总结,有不足的地方望大家多提宝贵意见。

 

(1)在Layout资源文件中,CheckBox的属性可以根据你人的不同用法做相应的改变,这个是我在做淘宝客户端的时候的应用,但加黑处:android:button=”资源文件中的对应属性值文件,check_but
是一个xml文件,其内容为以下所示。”

<CheckBox

       android:id="@+id/checkIn"

      android:layout_width="wrap_content"

      android:layout_height="wrap_content"

       android:checked="false"

       android:focusableInTouchMode="false"

      android:button="@drawable/check_but"

      

     ></CheckBox>

 

 

Check_but.xml的内容(附有用到的变换图片

 













 

<?xmlversion="1.0" encoding="utf-8"?>

<selectorxmlns:android="http://schemas.android.com/apk/res/android">

       <!--已经选中 -->

       <item android:state_window_focused="false"android:state_enabled="true"

              android:state_checked="true"android:drawable="@drawable/btn_check_on" />

              <!--未被选中 -->

       <itemandroid:state_window_focused="false"android:state_enabled="true"

              android:state_checked="false"android:drawable="@drawable/btn_check_off"></item>

       <!--已经选中,且被按下-->

       <itemandroid:state_enabled="true" android:state_checked="true"

              android:state_pressed="true"android:drawable="@drawable/btn_check_on_pressed"></item>

       <!--未被选中,且被按下-->

       <item android:state_enabled="true"android:state_checked="false"

              android:state_pressed="true"android:drawable="@drawable/btn_check_off_pressed"></item>

       <!--已经选中,且被聚焦-->

       <itemandroid:state_focused="true" android:state_enabled="true"

              android:state_checked="true"android:drawable="@drawable/btn_check_on_selected"></item>

       <!--未被选中,且被聚焦 -->

       <itemandroid:state_focused="true" android:state_enabled="true"

              android:state_checked="false"android:drawable="@drawable/btn_check_off_selected"></item>

 

</selector>
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: