I am creating one application in which I am searching for a Perticular word in text view.I have one edit text,one text view and one button,when I am entering any word in edit text and clicking on button it gives me the line position and position of word in that line from entire text file…I have append text file’s contain in text view…now my question is can I highlight that all word which is there in text view entered by edit text.?if I can than please tell me how to do it..if any one have idea of it?
Share
You can also do it by using a Spannable, which is convenient as you know the position of the word:
Where
entireStringis the string in which the word to highlight exists,coloris the color you want the hightlighted text to have,startis the position of the word andendis where the word ends (start+word.length()).The SpannableString res can then be applied to your textview like a regular string:
Note: If you want the background of the text to get a color rather than the text itself, use a
BackgroundColorSpaninstead of aForegroundColorSpan.Edit:
In your case it would be something like this (you will have to save the value of linecount and indexfound for when you read the entire text):