Android 自定义的CheckBox

来源:互联网 发布:王者荣耀 女娲 知乎 编辑:程序博客网 时间:2024/05/16 17:59

在项目的开发当中,会想要美观一点的CheckBox,我们会需要自定义CheckBox。

1,在布局文件中,添加

 <CheckBox                    android:id="@+id/cb_choose"                    style="@style/MyCheck_Box"                    android:layout_width="30dp"                    android:layout_height="wrap_content"                    android:layout_margin="10dp"                    android:clickable="true"                    android:gravity="center" />
2.在styles.xml文件中,添加样式。

    <!-- 自定义的checkBox -->    <style name="MyCheck_Box" parent="@android:style/Widget.CompoundButton.CheckBox">        <item name="android:button">@drawable/check_box_selector</item>    </style>
3.在drawable文件夹中,添加check_box_selector.xml。具体的CheckBox的样式。
<?xml version="1.0" encoding="utf-8"?><selector xmlns:android="http://schemas.android.com/apk/res/android">    <item android:drawable="@drawable/check_press_feng" android:state_checked="true"/>    <item android:drawable="@drawable/check_normal_feng" android:state_checked="false"/>    <item android:drawable="@drawable/check_normal_feng"></item></selector>



0 0
原创粉丝点击