Android CheckBox样式

来源:互联网 发布:大数据网站有哪些 编辑:程序博客网 时间:2024/05/12 11:27
  • 选中时候效果
    选中
  • 取消选中效果
    没选中

1.先在drawable目录下定义一个样式文件

<selector xmlns:android="http://schemas.android.com/apk/res/android">    <item android:drawable="@drawable/login_auto_check_true" android:state_checked="true"/>    <item android:drawable="@drawable/login_auto_check_false" android:state_checked="false"/></selector>

其中login_auto_check_true、login_auto_check_false 为选中和没选中的图片。

2.定义好了样式文件后直接在CheckBox控件中引用就行了

<CheckBox                android:id="@+id/cb_auto_login"                android:layout_width="wrap_content"                android:layout_height="wrap_content"                android:button="@drawable/login_auto_check"                android:checked="true" />
1 0
原创粉丝点击