在需要用到TextView的复制的功能的时候,我们只需要在xml文件中加一行代码就行:
<TextView
android:id="@+id/item_alertDetailInfo_tvSolveTime"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textIsSelectable="true"/>
设置textIsSelectable为true即可,但是这里有个巨坑,即便设置了这个属性,有时候还是会不能复制,于是百度良久发现如下答案答案
原因如下:
it works because the TextView has to layout again. You can trace the setText method to understand why. But layout a view is expansive. It’s an old bug of Android which google just don’t want to fix it.
解决办法:修改TextView的宽度为wrap_content即可,真是个巨坑-。-