Флажок для Android - PullRequest
       7

Флажок для Android

0 голосов
/ 03 октября 2018

Я пытаюсь использовать флажок с приведенной ниже конфигурацией макета.

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

Я не могу найти способ: - Избегать нажатия на текст.Я могу поставить / снять флажок, нажав на текст. - Добавьте контур вокруг квадрата / квадрата, чтобы сделать его более заметным для использования.

Есть идеи?

1 Ответ

0 голосов
/ 03 октября 2018

Если вы не хотите, чтобы текст был кликабельным, вы можете заменить один тег <CheckBox> на <LinearLayout>, содержащий <CheckBox> и <TextView>.Например, это:

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