我在android app里用RecyclerView加载数据列表,列表项的视图布局文件里有一个TextView,用户长按这个TextView,需要能够进行文本选择和复制。

我直接使用了android自带的文本选择和复制功能,即设置该TextView的属性android:textIsSelectable=“true”,但是测试过程中发现长按该TextView时,有时能弹出window,有时却不能。

在这里插入图片描述

后来在
https://stackoverflow.com/questions/36801486/androidtextisselectable-true-not-working-for-textview-in-recyclerview
找到了解决方法,将该TextView的android:layout_width="match_parent"修改为android:layout_width=“wrap_content”,问题解决。

<TextView
        android:id="@+id/tv_msg"
        android:textSize="14sp"
        android:textColor="@color/color_333333"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginRight="@dimen/dp_20"
        android:layout_marginLeft="@dimen/dp_20"
        android:paddingBottom="@dimen/dp_12"
        android:textIsSelectable="true"/>
Logo

为开发者提供学习成长、分享交流、生态实践、资源工具等服务,帮助开发者快速成长。

更多推荐