`
xindrace
  • 浏览: 93761 次
  • 性别: Icon_minigender_1
  • 来自: 北京
社区版块
存档分类
最新评论

更改CheckBox的样式

 
阅读更多

首先在styles.xml添加如下的自定义样式:

<style name="mycheckbox" parent="@android:style/Widget.CompoundButton.CheckBox">
<item name="android:button">@drawable/my_checkbox</item>
</style>

 my_checkbox.xml的内容为:

<?xml version="1.0" encoding="utf-8"?>

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

        <item android:state_checked="true" android:drawable="@drawable/checkbox_pressed" />                                                                                       
    <item android:state_checked="false" android:drawable="@drawable/checkbox" />

     <item android:drawable="@drawable/checkbox" />                                                                                                
</selector>

 

使用自定义样式的代码段:

<CheckBox
   android:id="@+id/checked" 
   android:layout_alignParentRight="true"
   android:layout_marginRight="10dip"
   android:layout_centerVertical="true"
   android:layout_width="40dip" 
   android:layout_height="wrap_content"
   android:checked="false"
   style="@style/mycheckbox" 
   />

 添加两张图片checkbox_pressed.png、checkbox.png

  • 大小: 302 Bytes
  • 大小: 553 Bytes
分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics