mas true 我们 you andro content style ted
大部分情况下,我们在 UI 中并不採用 android 自带的 checkbox 复选框样式,这时候就须要我们自己定义自己的 checkbox。
首先找两张 checkbox 背景图片。比方下图样子的:
然后在 drawable 文件夹下定义一个背景图片 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/fuxuan_input01"
- />
- <item android:state_selected="true" android:drawable="@drawable/fuxuan_input01">
- </item>
- <item android:state_pressed="true" android:drawable="@drawable/fuxuan_input01">
- </item>
- <item android:state_checked="false" android:drawable="@drawable/fuxuan_input02"
- />
- </selector>
在须要用到 checkbox 的地方定义它。属性设置例如以下代码所看到的:
自己定义 checkbox 就此完毕,效果例如以下图所看到的:
- <CheckBox
- android:id="@+id/agree_provision_chk"
- android:layout_width="wrap_content"
- android:layout_height="wrap_content"
- android:background="@drawable/chk_agee_provision_background"
- android:button="@null" />
Android 之自己定义 checkbox 样式
来源: http://www.bubuko.com/infodetail-2045234.html