简体   繁体   English

Android textIsSelectable 停止 TextView onClick 工作正常

[英]Android textIsSelectable stops TextView onClick working correctly

In my current Android application I have a MaterialCardView that wraps a TextView that I wish to be copyable eg I use在我当前的 Android 应用程序中,我有一个MaterialCardView包装了一个TextView我希望是可复制的,例如我使用

android:textIsSelectable="true"

However, I also need to know when the MaterialCardView is clicked as its within a RecyclerView Item layout.但是,我还需要知道何时在RecyclerView项目布局中单击MaterialCardView

My onClickListener for the MaterialCardView is only triggered when I remove the android:textIsSelectable="true" attribute from the child TextView .仅当我从子onClickListener中删除android:textIsSelectable="true"属性时,才会触发MaterialCardViewTextView

here is the complete RecyclerView Item layout这是完整的 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>

How can I both detect clicks on the Parent MaterialCardView and have the child TextView selectable?我怎样才能检测到对父MaterialCardView的点击并让子TextView可选?

In your case (with textIsSelectable="true" ) the TextView will still trigger an OnClick event.在您的情况下(使用textIsSelectable="true"TextView仍将触发OnClick事件。 So you could simply add an OnClickListener to your TextView and link that to the existing CardView click behavior.因此,您可以简单地将TextView OnClickListener其链接到现有的 CardView 点击行为。

Would that cover your case?这会涵盖你的情况吗?

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 “android:textIsSelectable=”true” 不适用于 RecyclerView 中的 TextView - “android:textIsSelectable=”true" not working for TextView in RecyclerView textview textIsSelectable =“true”在Listview中不起作用 - textview textIsSelectable=“true” not working in Listview 添加android:textIsSelectable会导致TextView自动滚动 - Adding android:textIsSelectable causes TextView to autoscroll 使用android:textIsSelectable =“ true”复制文本不适用于android中同一textview上的onClicklistner - Copy text using android:textIsSelectable=“true” is not working with onClicklistner on same textview in android textview 上的 Onclick 事件(具有 TextIsSelectable="true")仅在第二次单击时调用 - Onclick event on textview(that has TextIsSelectable="true") is ony called on second click 单击 TextView 后,Android 应用程序停止工作 - Android application stops working after clicking on TextView 在textView中使用textIsSelectable - using textIsSelectable in textView android:textIsSelectable =“ true”在Listview内的TextView不起作用 - android:textIsSelectable=“true” for TextView inside Listview does not work 建筑物错误:从删除属性android:textIsSelectable <TextView> - Building Error: removing attribute android:textIsSelectable from <TextView> textIsSelectable使TextView滚动 - textIsSelectable is making TextView scroll
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM