我正在製作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? –