TextView 可点击在 LinearLayout 按钮内自动启用

问题描述

自从我将我的项目更新到 30 级和 android studio 到 4.2 以来,我一直遇到一个非常烦人的问题。我所有的可点击视图都有一个奇怪的问题,我有一些线性布局、相对布局设置为可点击和一个 onClickListener,这在此更新之前完美无缺。

但是现在当我尝试单击此布局按钮之一时,我只能单击视图的外部而不是任何子组件,例如:

<LinearLayout
    android:id="@+id/basket_expand"
    android:clickable="true"
    android:focusable="true"
    android:padding="12dp"
    android:focusableInTouchMode="true"
    android:background="@drawable/rounded_green"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:orientation="horizontal"
    android:layout_gravity="center_vertical">

    <TextView
        android:background="@drawable/dark_rounded_green"
        android:padding="5dp"
        android:id="@+id/order_items"
        android:enabled="false"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="@string/zero"
        android:textColor="@android:color/white"
        android:textSize="18sp"
        android:textStyle="bold" />

    <TextView
        android:id="@+id/basket_button_text"
        android:layout_width="0dp"
        android:layout_height="wrap_content"
        android:layout_marginBottom="10dp"
        android:layout_weight="1"
        android:clickable="false"
        android:textAlignment="center"
        android:textColor="@android:color/white"
        android:text="@string/open_basket"
        android:textSize="18sp"
        android:textStyle="bold" />

    <TextView
        android:id="@+id/order_total"
        android:layout_width="wrap_content"
        android:gravity="end"
        android:layout_height="wrap_content"
        android:textColor="@android:color/white"
        android:textStyle="bold"
        android:textSize="15sp"
        android:text="$0"
        tools:ignore="HardcodedText" />
</LinearLayout>

在此视图中,我无法单击三个文本,只是当我单击线性布局的边框时,单击将触发,单击 textViews 时,我可以看到在 Profiler 中调用了一个按下事件,但未调用父 onClick 事件.

我检查了布局检查器,尽管它仍然显示为启用的文本视图的硬编码可点击错误:

来自 xml:

android:clickable="false"

在布局检查器中运行应用程序时:

enter image description here

在我的 kotlin 代码或任何其他部分中,我没有将可点击设置为 true 的地方。我试过启用和禁用一些属性,但没有任何变化,例如descendantFocusability,将clickable 和focusable 设置为false 给孩子,似乎没有任何效果。任何想法为什么会发生这种情况?谢谢。

编辑:如果我单击一个随机按钮并添加到 onclick 侦听器 isClickable false 到 textviews 父视图单击工作,但这真的很麻烦,它不会在 recyclerview (发生这种情况的一个测试用例)

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)