【发布时间】:2020-12-03 18:08:30
【问题描述】:
在我当前的 Android 应用程序中,我有一个 MaterialCardView 包装了一个 TextView,我希望它是可复制的,例如我用
android:textIsSelectable="true"
但是,我还需要知道 MaterialCardView 何时在 RecyclerView 项目布局中被点击。
仅当我从子 TextView 中删除 android:textIsSelectable="true" 属性时,才会触发 MaterialCardView 的 onClickListener。
这是完整的 RecyclerView 项目布局
<?xml version="1.0" encoding="utf-8"?>
<com.google.android.material.card.MaterialCardView xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:card_view="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/item_bibtext_cardview"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:clickable="true"
android:focusable="true"
card_view:cardBackgroundColor="?attr/colorSurface"
card_view:cardCornerRadius="10dp"
card_view:cardElevation="5dp"
card_view:cardPreventCornerOverlap="false"
card_view:cardUseCompatPadding="true"
card_view:contentPadding="10dp">
<TextView
android:id="@+id/bibtex"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:textIsSelectable="true"
android:background="?android:attr/selectableItemBackground"
android:textColor="?android:attr/textColorPrimary" />
</com.google.android.material.card.MaterialCardView>
如何既检测到对父 MaterialCardView 的点击,又让子 TextView 可选择?
【问题讨论】:
标签: android onclicklistener materialcardview