如何在textview android代码中触摸文本时选择并突出显示一个或多个段落 谢谢!
答案 0 :(得分:0)
这是一个想法..
插入颜色的HTML代码,然后将其设置为您的文本。
代码中的"<font color='red'>"+textToHighlight+"</font>"
。
或强>
添加带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
或
启用TextView的Spannable存储。(默认情况下,EditText中的Spannable存储为真。)
TextView myTV = (TextView)findViewById(R.id.textView1);
String textString = "StackOverFlow Rocks!!!";
Spannable spanText = Spannable.Factory.getInstance().newSpannable(textString);
spanText.setSpan(new BackgroundColorSpan(0xFFFFFF00), 14, 19, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
myTV.setText(spanText);