You can also do this using Spannable , which is convenient since you know the position of the word:
SpannableString res = new SpannableString(entireString); res.setSpan(new ForegroundColorSpan(color), start, end, SpannableString.SPAN_EXCLUSIVE_EXCLUSIVE);
Where entireString is the line where the highlighted word exists, color is the color you need to have tanned text, start is the position of the word, and end is where the word ends (start + word.length ()).
Then SpannableString res can be applied to your texture as a regular string:
textView.setText(res);
Note. If you want the background of the text to get color rather than the text itself, use BackgroundColorSpan instead of ForegroundColorSpan .
Edit: In your case, it will be something like this (you will need to save the value of linecount and indexfound when reading the entire text):
for(String test="", int currentLine=0; test!=null; test=br2.readLine(), currentLine++){ if(currentLine==linecount){ SpannableString res = new SpannableString(test); res.setSpan(new ForegroundColorSpan(0xFFFF0000), indexfound, indexfound+textword.length(), SpannableString.SPAN_EXCLUSIVE_EXCLUSIVE); } tv.append("\n"+" "+test); }
source share