我正在制作android应用程序,它必须检查列表中是否有任何单词并突出显示它们。我尝试下面的代码:EditText突出显示文本
public void checkSyntax() {
//Text variable
data = et.getText().toString();
//Colored text
Spanned text = Html.fromHtml("<font color=\"red\">text</font>");
Spanned smth = Html.fromHtml("<font color=\"green\">its just example</font>");
Spanned owo = Html.fromHtml("<font color=\"blue\">i know html</font>");
//Replace words to colored text in string
data.replace("text", text);
data.replace("smth", smth);
data.replace("owo", owo);
//Set new text
et.removeTextChangedListener(tw);
et.setText(data);
et.addTextChangedListener(tw);
}
您是否尝试过使用TextWatcher? –