Android 的复选框

Checkbox for Android

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

<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"/>

我找不到方法来: - 避免文本可点击。我可以通过点击文本来 check/uncheck 方框 - 在复选框周围添加 round/square 轮廓,使其更易于使用。

有什么想法吗?

如果您不希望文本可点击,您可以将单个 <CheckBox> 标签替换为包含 <CheckBox><TextView><LinearLayout>。例如,这个:

<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>

如果您想在复选框周围画一个方框以使其更加突出,您可以将其包裹在一个 <FrameLayout> 中并带有彩色背景:

<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>