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

标签 android android-recyclerview textview

我知道在 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/

相关文章:

java - 接口(interface)值始终为空

android - 无法检查我的textview在Kotlin中是否可见数组内部

java - 在 Android 中使用 autoSizeColumn 方法时 FontRenderContext 错误

android - 如何判断操作系统是否是来自应用程序的自定义 ROM?

android - SwipeRefreshLayout 阻止水平滚动的 RecyclerView

android - 从 ViewPager 中的 FragmentActivity 获取 Fragment 中 TextView 的 id

java - 循环TextView并设置大小

java - 在 android 的 webView 中打开 Url

Android - DatePicker onDateChanged 前后值

android - 在刷新期间使用 SwipeRefreshLayout 切换 fragment 时, fragment 卡住但实际上仍然有效