我有一个 TextView
,我想允许用户从其中选择一定范围的文本。 TextView
占据了设备的整个宽度和高度(减去一些填充和顶部的标题)。在 EditText
中,如果您长按,您会得到一个选择叠加层,允许您设置选择的左右边界。我想在 TextView
中使用此功能。我读过 API 级别 9 (2.3) (http://developer.android.com/sdk/android-2.3.html) 中有新的文本选择控件,但我很难实现它。我现在正在这样做:
eic = new InputConnection( bookTextView );
eic.beginBatchEdit();
但它并没有做任何值得注意的事情。有谁知道如何正确使用 InputConnection
?谢谢。
编辑:我不一定需要使用我在上面尝试的内容。我最终想使用 TextView
或 EditText
,它看起来和感觉都像 TextView
并且能够使用拖动光标选择文本。然后我想使用各种上下文菜单选项(或在所选文本上方弹出的菜单)来操作所选文本。
最佳答案
这是一个想法.. 添加一个带有 TextView 背景的 EditText,这是一个例子
<EditText
android:text=" This is not an editable EditText"
android:id="@+id/EditText01"
android:layout_width="wrap_content"
android:textColor = "@android:color/white"
android:editable = "false"
android:cursorVisible="false"
android:layout_height="wrap_content"
android:background = "@android:drawable/dark_header">
</EditText>
将它添加到您的 xml 中,代替 TextView
关于android - 如何允许用户在 TextView 中选择文本范围(类似于 EditText),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6309093/