I am having a webview. I am just retrieving the webview's content in a string and displaying it in textview. In onTouch event the text will read aloud. Now i want to highlight the text word by word in onTouch event which the text is speaking. For textview we can use setTextColor. But how to setTextColor for string?
            Asked
            
        
        
            Active
            
        
            Viewed 68 times
        
    0
            
            
        
        Gayu R
        
- 41
 - 6
 
2 Answers
0
            
            
        Use a SpannableString, for example:
final String s = editText.getText().toString();
final Spannable spannable = new SpannableString(s);
spannable.setSpan(new ForegroundColorSpan(Color.RED), 0, endIndex, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
Update the endIndex to point to the end of whatever word is being spoken,
        PPartisan
        
- 8,173
 - 4
 - 29
 - 48
 
0
            
            
        Just use like this too
String name = "Test String"; 
textView.setText( Html.fromHtml(String.format("<font color=\"#%s\">text</font>", name ), TextView.BufferType.SPANNABLE));
        The Bala
        
- 1,313
 - 1
 - 15
 - 23