gpt4 book ai didi

android - "android:textIsSelectable="true"RecyclerView中TextView不工作

转载 作者:IT老高 更新时间:2023-10-28 22:14:59 38 4
gpt4 key购买 nike

我知道在 TextView 的 xml 中设置 android:textIsSelectable="true" 将显示 native 文本选择弹出窗口,我一直在我的应用程序中使用它.但是当我尝试在附加到 RecyclerView 的 View 中设置相同的属性时,我发现它不再起作用了。每当我尝试选择文本时,都会出现以下日志 -

TextView: TextView does not support text selection. Action mode cancelled.

我不知道为什么?为什么它适用于其他屏幕而不适用于 RecyclerView。我阅读了多篇文章-

TextView with android:textIsSelectable="true" not working in listview

textview textIsSelectable="true" not working in Listview

android:textIsSelectable="true" for TextView inside Listview does not work

但后来我遇到了这个帖子-

Android: "TextView does not support text selection. Action mode cancelled"

@hungkk 的回复对我有用。他的解决方案建议将 TextView 宽度从 match_parent 更改为 wrap_content

我知道我可以做到这一点,但我的问题是这如何解决问题,因为它对我来说看起来很奇怪。另外,如果我想保持 match_parent 的宽度,解决方案是什么。

欢迎提出任何意见。

最佳答案

在recyclerview的主父布局中添加属性

android:descendantFocusability="beforeDescendants"

然后在rowitem布局的TextView中添加

android:textIsSelectable="true"

关于android - "android:textIsSelectable="true"RecyclerView中TextView不工作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36801486/

38 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com