Android TextIsSelectable使TextView onClick无法正常工作 [英] Android textIsSelectable stops TextView onClick working correctly

查看:42
本文介绍了Android TextIsSelectable使TextView onClick无法正常工作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

android:textIsSelectable="true"

但是,我还需要知道MaterialCardViewRecyclerView项布局中被单击的时间。

仅当从子TextView中删除android:textIsSelectable="true"属性时,才会触发MaterialCardViewonClickListener

以下是完整的RecEconerView项目布局

<?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可选?

推荐答案

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

这能涵盖您的情况吗?

这篇关于Android TextIsSelectable使TextView onClick无法正常工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆