如何解决升级到 compileSdkVersion 30 后 onClick 无法正常工作
我的项目是 29 sdk 版本,它完美运行,但我决定升级到 30 以及我的库和 gradle,这些是我所做的一些主要升级:
- gradle-7.0.2
- com.android.tools.build:gradle:4.2.1
- androidx.core:core-ktx:1.5.0
- androidx.appcompat:appcompat:1.3.0
我修复了一些不推荐使用的代码(主要使用新的 startActivityForResult 流程)
但这是我的问题,之后我所有的点击监听器都无法正常工作,例如我有这个视图结构:LinearLayout -> TextView。我在 LinearLayout 上有一个 onclick 事件,但是单击事件仅在我单击线性布局的边框而不是在 textview 顶部时才会发生,如果我单击 textview 没有任何反应,但是我的项目中的每一个 onclick 都会发生这种情况,这之前运行得很好,现在这是 android 中的新功能吗?如何禁用此功能?
这是示例视图,它是水平 recyclerView 的一部分
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/card_rca"
android:padding="10dp"
android:layout_margin="5dp"
android:clickable="true"
android:focusable="true"
android:foreground="?android:attr/selectableItemBackground"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="wrap_content"
android:layout_height="wrap_content">
<TextView
android:textColor="@color/lightGray"
android:id="@+id/text_category"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
</LinearLayout>
这是点击监听器
categoryContainer.setonClickListener {
// do some filtering ...
}
我尝试过的事情: 添加到文本视图
android:clickable="false"
android:focusable="false"
android:textIsSelectable="false"
但我就是不明白,为什么现在要这样做?关于为什么会发生这种情况的任何见解?有人遇到同样的事情吗?
谢谢
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。