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>
相关推荐
好的佩奇40 分钟前
蓝牙之通信架构
android·flutter·蓝牙
FlightYe1 小时前
视界原理之3D视频(四):裸眼、眼镜和头显
android·linux·c++·3d·ffmpeg·音视频
诸神黄昏EX2 小时前
Android fw BatteryService
android
alexhilton2 小时前
提升 Android Compose 页面的流畅度
android·kotlin·android jetpack
撩得Android一次心动4 小时前
Android中Gradle网络下载超时、更改存放位置(解决方案)
android·gradle
HQL_seven5 小时前
【Activity】Android Activity详解
android
AI2中文网5 小时前
安卓 15/16 手机软键盘遮挡输入框、布局顶不上去?已解决:重新编译即可
android·智能手机
字节暗面5 小时前
Android APP 加固横评记录:爱加密、梆梆、网易易盾与腾讯 ACE
android·逆向工程·加固
落魄Android在线炒饭6 小时前
Android 实战问题反推 OpenGL 概念(上)
android·opengl
booboosui6 小时前
DeepSeek 的 Worker 调得动 GitHub,调不动微信:三类 Worker 的实现差别
android