I know, but its (as far as I know?) The only way to mark text in an EditText control.
EditText supports Spannable
objects, so you can apply primary colors to text (such as background colors) yourself.
This sample project demonstrates a search box that uses the background color for most of the text based on the search results. The key part is the searchFor()
method:
private void searchFor(String text) { TextView prose=(TextView)findViewById(R.id.prose); Spannable raw=new SpannableString(prose.getText()); BackgroundColorSpan[] spans=raw.getSpans(0, raw.length(), BackgroundColorSpan.class); for (BackgroundColorSpan span : spans) { raw.removeSpan(span); } int index=TextUtils.indexOf(raw, text); while (index >= 0) { raw.setSpan(new BackgroundColorSpan(0xFF8B008B), index, index + text.length(), Spanned.SPAN_EXCLUSIVE_EXCLUSIVE); index=TextUtils.indexOf(raw, text, index + text.length()); } prose.setText(raw); }
Note that your "output string" should probably be a TextView
, not an EditText
. EditText
is for input, not output.
source share