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>
相关推荐
pengyu2 小时前
【Kotlin 协程修仙录 · 大乘境 · 初阶】 | 跳出三界:协程在 KMP 与后端开发中的跨平台之道
android·kotlin
XiaoLeisj2 小时前
Android Memory Profiler:堆内存指标、内存抖动与泄漏定位
android·性能优化·内存抖动·内存泄露·memory profiler
未来猫咪花2 小时前
Everything is ViewModel:让状态管理回到对象世界
android·flutter·ios
古法安卓2 小时前
Android-重启流程源码解析
android·java·android studio
协议的旁观者3 小时前
Android 高级逆向实战(一):对抗 360 企业加固,Native 抽取还原与 Activity 生命周期重建
android
mmsx6 小时前
osmdroid 屏幕坐标与测量坐标互转:中心点+比例尺仿射换算
android·源码·地图·osmdroid
00后程序员张6 小时前
Android证书绑定抓包失败?Android SSL Pinning绕过实战指南
android·网络协议·计算机网络·网络安全·adb·https·ssl
杉氧6 小时前
页面栈与路由:React Navigation 与 Expo Router 深度实践
android·前端·react native
XiaoLeisj6 小时前
Jetpack Compose 知识点
android·kotlin·android jetpack·compose