7

我有一个SwitchCompat

<android.support.v7.widget.SwitchCompat
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:text="Some title"/>

我想防止点击文本标题。当我单击文本标题时,切换开关。但我只想在单击切换图标时进行切换。

可能吗?或者我是否必须为此创建两个单独views的:一个TextView用于标题,一个SwitchCompat没有文本?

在此处输入图像描述

4

2 回答 2

0

我没有找到这个问题的确切解决方案,但你可以像这样分开 TextView 和 Swich:

<RelativeLayout
    android:layout_width="wrap_content"
    android:layout_height="match_parent">
    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="YOUR SWITCH TEXT HERE"/>
    <Switch
        android:id="@+id/switch"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentRight="true" />
</RelativeLayout>

并在您的代码中使用开关 setOnCheckedChangeListener。

于 2019-10-19T11:08:08.997 回答
-4

添加这个:

android:clickable="true"
android:focusable="true"
于 2016-01-13T11:54:02.303 回答