【发布时间】:2018-08-01 02:42:53
【问题描述】:
我想在 android textview 中突出显示选定的文本。谁能告诉我在 android textview 中获取选定文本的开始和结束索引的可能性。
我使用以下 TextView 来选择文本。
<TextView
android:id="@+id/textview"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Hello World!"
android:textIsSelectable="true"
android:bufferType="spannable"
/>
为了突出显示特定字符串,我使用以下代码。如何获取所选文本的开始和结束索引。
SpannableString str = new SpannableString("Highlighted. Not highlighted.");
str.setSpan(new BackgroundColorSpan(Color.YELLOW), 0, 11, 0);
textView.setText(str);
【问题讨论】:
-
某人如何从文本视图中选择文本。请详细解释。
-
我不知道有人在不理解或回答我的问题的情况下投反对票。他们必须在不投反对票的情况下添加评论。
-
@DanieleD。我的问题与您建议的答案不同。
标签: android textview highlight