Highlight Text in TextView or WebView
enable TextView's Spannable storage! by default Spannable storage in EditText is true.
so
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);
As well you could use this one solution for WebView
. Call findAllAsync
webview.findAllAsync(((EditText) findViewById(R.id.edit)).getText().toString());
than add FindListener
to WebView
webview.setFindListener(new FindListener() {
@Override
public void onFindResultReceived(int activeMatchOrdinal, int numberOfMatches, boolean isDoneCounting) {
Toast.makeText(getApplicationContext(), "Matches: " + numberOfMatches, Toast.LENGTH_LONG).show();
}
});
Iterate in result with webview.findNext(false);
where false/true shows the direction.
But this solution was added in API level 16
!!! Instead of you can setup JavaScript for higlihting - http://www.nsftools.com/misc/SearchAndHighlight.htm