我有一个webview
。我只是在webview's
中检索string
内容,并在textview
中显示它。在onTouch
事件中,文本将大声朗读。现在,我想在onTouch
事件中逐字突出显示文本。对于textview
,我们可以使用setTextColor
。但是如何setTextColor
输入字符串呢?
答案 0 :(得分:0)
使用SpannableString
,例如:
final String s = editText.getText().toString();
final Spannable spannable = new SpannableString(s);
spannable.setSpan(new ForegroundColorSpan(Color.RED), 0, endIndex, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
更新endIndex
使其指向所讲单词的结尾,
答案 1 :(得分:0)
也这样使用
String name = "Test String";
textView.setText( Html.fromHtml(String.format("<font color=\"#%s\">text</font>", name ), TextView.BufferType.SPANNABLE));