android-控件-多选框CheckBox

实例1-自定义风格

html 复制代码
   <LinearLayout
                    android:layout_width="match_parent"
                    android:layout_height="0dp"
                    android:layout_weight="10"
                    android:orientation="horizontal"
                    tools:ignore="Suspicious0dp">
                    <CheckBox
                        android:id="@+id/channel_1"
                        style="@style/test3_dialogtree_checkbox"
                        android:text="通道1"/>

                    <CheckBox
                        android:id="@+id/channel_2"
                        style="@style/test3_dialogtree_checkbox"
                        android:text="通道2" />
                    <CheckBox
                        android:id="@+id/channel_3"
                        style="@style/test3_dialogtree_checkbox"
                        android:text="通道3" />

                    <CheckBox
                        android:id="@+id/channel_4"
                        style="@style/test3_dialogtree_checkbox"
                        android:text="通道4" />

                    <CheckBox
                        android:id="@+id/channel_5"
                        style="@style/test3_dialogtree_checkbox"
                        android:text="通道5" />
                    <CheckBox

                        style="@style/test3_dialogtree_checkbox"
                        android:text="通道6" />
                    
                </LinearLayout>
html 复制代码
    <style name="test3_dialogtree_checkbox">
        
        <item name="android:layout_width">0dp</item>
        <item name="android:layout_height">match_parent</item>
        <item name="android:layout_weight">1</item>
        <item name="android:textSize">20sp</item>
        <item name="android:padding">12dp</item>
        <item name="android:minHeight">50dp</item>     <!-- 最小高度 -->
        <item name="android:minWidth">50dp</item>      <!-- 最小宽度 -->
        <item name="android:button">@drawable/custom_checkbox_large</item>  <!-- 自定义复选框 -->
    </style>

drawable中custom_checkbox_large.xml

html 复制代码
<selector xmlns:android="http://schemas.android.com/apk/res/android">
    <!-- 选中状态 -->
    <item android:state_checked="true">
        <shape android:shape="rectangle">
            <stroke android:width="3dp" android:color="#2196F3" />
            <solid android:color="#2196F3" />
            <size android:width="25dp" android:height="25dp" />  <!-- 放大到 40x40 -->
        </shape>
    </item>

    <!-- 未选中状态 -->
    <item>
        <shape android:shape="rectangle">
            <stroke android:width="2dp" android:color="#666666" />
            <size android:width="25dp" android:height="25dp" />  <!-- 放大到 40x40 -->
        </shape>
    </item>
</selector>
相关推荐
千里马学框架11 小时前
一起学 Android 14:ShellTransition 屏幕旋转过程深度剖析
android·智能手机·性能优化·framework·性能·屏幕旋转·rotation
美狐美颜SDK开放平台11 小时前
开发直播APP时如何接入视频美颜SDK?开发流程与注意事项
android·人工智能·计算机视觉·音视频·直播美颜sdk
AFinalStone11 小时前
Android7 SystemUI源码解析(七)Keyguard锁屏模块深度解析
android·systemui
致远ccc12 小时前
Google Play 上架前如何测试 App?多国家 Android 环境测试
android·app测试·googleplay·多国家应用测试
ttyyttemo14 小时前
Kotlin 协程中的 Job 结构化并发与取消
android
71777714 小时前
研发平台选哪家比较好:2026年主流平台对比与Gitee选型指南
人工智能·gitee
sun00770014 小时前
tbox 4g/5g切换,导致wan ip 改变,导致车机旧网络不可用。需要重启车机才行
android
其实防守也摸鱼15 小时前
内网穿透与反向代理:原理、工具与实战指南
android·大数据·运维·安全·网络安全·自动化·渗透
AFinalStone16 小时前
Android7 SystemUI 源码解析(四)NavigationBar 导航栏与 SystemBars
android·systemui
JMchen16 小时前
属性动画原理与高级动画实现
android·kotlin·canvas