Checkbox_radioButton自定义



<CheckBox
            android:id="@+id/cbox_pay_way_zhifubao"
            style="@style/shop_bag_cbox"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_marginRight="@dimen/x28"
            android:checked="true"/>

            
<style name="shop_bag_cbox" parent="@android:style/Widget.CompoundButton.CheckBox">
        <item name="android:button">@drawable/bm_selector_shop_cbox</item>
    </style>
    
    <?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/bm_icon_circle"/>
    <item android:state_checked="false"  android:drawable="@drawable/bm_icon_circle_no"/>
    <item android:drawable="@drawable/bm_icon_circle_no"/>
</selector>


<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent">


    <CheckBox
        android:id="@+id/checkbox"
        android:layout_centerInParent="true"
        style="@style/custom_check_box"
        android:checked="true"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content" />

    <RadioButton
        android:layout_marginTop="10dp"
        android:layout_below="@id/checkbox"
        android:layout_centerHorizontal="true"
        style="@style/custom_check_box"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content" />
</RelativeLayout>

  <style name="custom_check_box" parent="Base.Widget.AppCompat.CompoundButton.CheckBox">
        <item name="android:button">@drawable/selector_check_box_style</item>
    </style>


<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
    <item android:drawable="@drawable/ic_unselected" android:state_checked="true" />
    <item android:drawable="@drawable/ic_selected" android:state_checked="false" />
    <item android:drawable="@drawable/ic_selected" />
</selector>

这个checkbox可以是选择和反选

而 radioButton只能是选择, 没有反选, 所以不常用啦

自定义checkbox样式

自定义radioButton样式

©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容

  • Android 自定义View的各种姿势1 Activity的显示之ViewRootImpl详解 Activity...
    passiontim阅读 175,785评论 25 709
  • 每次写这个“松”字,都觉得是有人盘腿坐在山顶一颗松前,被风吹乱了头发。 嗯,被吹成了中分头。
    苏白杞阅读 2,224评论 12 15