1

在我当前的 Android 应用程序中,我有一个MaterialCardView包装了TextView我希望可复制的,例如我使用

android:textIsSelectable="true"

但是,我还需要知道何时在项目布局MaterialCardView中单击它。RecyclerView

onClickListener的 forMaterialCardView仅在我android:textIsSelectable="true"从 child 中删除属性时触发TextView

这是完整的 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可选择?

4

1 回答 1

1

在您的情况下(使用textIsSelectable="true"),TextView仍然会触发OnClick事件。OnClickListener因此,您可以简单地添加一个TextView并将其链接到现有的 CardView 点击行为。

这会涵盖你的情况吗?

于 2020-12-03T10:08:30.293 回答