扩大AppCompatCheckBox点击区域(点击外部ViewGroup,内部AppCompatCheckBox选中状态切换)

本文介绍了如何扩大AppCompatCheckBox的点击区域,使得点击其外层ViewGroup时,内部的AppCompatCheckBox能正确切换选中状态。由于子View仅在视觉上继承了父View的状态,因此AppCompatCheckBox自身无法正确感知选中变化。解决方案包括使用CheckableLinearLayout来判断选中状态,或监听CheckableLinearLayout的点击事件手动更新AppCompatCheckBox状态。
摘要由CSDN通过智能技术生成
    <com.demo.CheckableLinearLayout
        android:layout_width="100dp"
        android:layout_height="100dp"
        android:background="#00ff00"
        android:gravity="center"
        android:orientation="vertical"
        app:layout_constraintTop_toTopOf="parent">

        <android.support.v7.widget.AppCompatCheckBox
            android:id="@+id/checkbox_favourite"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:clickable="false"
            android:duplicateParentState="true" />

        <TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:background="#ff0000"
            android:text="收藏"
     
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值