#CheckBox expand its click area ##CheckBox扩大点击区域

本文介绍了如何通过设置`android:drawableLeft`和`android:text`来自定义CheckBox样式,替代CheckBox与TextView组合的方式,以扩大CheckBox的点击区域。同时,提到了使用TouchDelegate来增加触控区域的技巧,并提供了Method 1的具体代码,包括styles.xml和不同状态的drawable selector。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

Method

  1. 用”android:drawableLeft“取代”android:background”来设置CheckBox的自定义样式;同时自身设置”android:text”来显示文字提示,取代CheckBox+TextView的模式
  2. 使用TouchDelegate,>引用[link text](“http://stackoverflow.com/questions/1343222/is-there-an-example-of-how-to-use-a-touchdelegate-in-android-to-increase-the-siz“)

  1. Method 1 具体代码:
    styles.xml

    <style name="check_box_orange">
        <item name="android:layout_width">wrap_content</item>
        <item name="android:layout_height">wrap_content</item>
        <item name="android:button">@null</item>
        <item name="android:drawableLeft">@drawable/selector_check_box_orange</item>
        <item name="android:drawablePadding">10dp</item>
        <!--optional-->
        <item name="android:singleLine">true</item>
        <item name="android:layout_marginLeft">15dp</item>
        <item name="android:textColor">@color/text_color_gray</item>
        <item name="android:textSize">@dimen/middle_text_size_14</item>
    </style>

    drawable selector 三种图片的状态

    <?xml version="1.0" encoding="utf-8"?>
    <selector xmlns:android="http://schemas.android.com/apk/res/android">
        <item android:drawable="@drawable/ic_checkbox_disable" android:state_enabled="false"></item>
        <item android:drawable="@drawable/ic_checkbox_checked" android:state_checked="true"></item>
        <item android:drawable="@drawable/ic_checkbox_normal"></item>
    </selector>
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值