Android的复选框

Android的复选框,android,android-checkbox,Android,Android Checkbox,我正在尝试使用以下布局配置的复选框 <android.support.v7.widget.AppCompatCheckBox android:id="@+id/gdprOptIn" fontPath="fonts/AvenirNextRegular.ttf" android:layout_width="match_parent" android:layout_height="wrap_conte

我正在尝试使用以下布局配置的复选框

<android.support.v7.widget.AppCompatCheckBox
            android:id="@+id/gdprOptIn"
            fontPath="fonts/AvenirNextRegular.ttf"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_gravity="center"
            android:layout_marginBottom="@dimen/medium_margin"
            android:layout_marginTop="@dimen/medium_margin"
            android:button="@drawable/checkbox"
            android:checked="false"
            android:paddingLeft="@dimen/default_margin"
            android:text="@string/opt_in_gdpr"
            android:textColor="@color/paper_ink_light"
            android:visibility="gone"
            android:gravity="top"/>

我找不到一个方法来: -避免文本被点击。我可以通过点击文本来勾选/取消勾选该框 -在复选框周围添加圆形/方形轮廓,使其更便于使用


有什么想法吗?

如果你不想让文本被点击,你可以用一个
标签替换一个
标签,其中包含一个
和一个
。例如,这:

<CheckBox
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:text="hello world"/>

可替换为:

<LinearLayout
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:orientation="horizontal">

    <CheckBox
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"/>

    <TextView
        android:layout_width="0dp"
        android:layout_height="wrap_content"
        android:layout_weight="1"
        android:text="hello world"/>

</LinearLayout>

如果您想在复选框周围画一个框,使其更加突出,可以将其包装成一个带有彩色背景的

<LinearLayout
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:gravity="center_vertical"
    android:orientation="horizontal">

    <FrameLayout
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:background="#fac">

        <CheckBox
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"/>

    </FrameLayout>

    <TextView
        android:layout_width="0dp"
        android:layout_height="wrap_content"
        android:layout_weight="1"
        android:text="hello world"/>

</LinearLayout>

谢谢,唯一的问题是我的文本是文本视图中的文本包含可单击元素,让我们的世界是可单击的。我使用了SpannableStringBuilder来创建它,但它似乎变得不可单击,或者单击事件被LinearLayout捕获。我已将LL设置为clickable:false,但仍然不起作用