Вы можете сделать это с помощью замены() метод, то Html.fromHtml(), как показано ниже
yourEditText.setOnFocusChangedListener(new OnFocusChangedListener(){
@Override
public void onFocusChange(View v, boolean hasFocus){
if (hasFocus){
if (str.contains("Hello how are you ?") == true)
{
str = ((EditText)v)getText.ToString().replaceAll("Hello how are you ?", "<font color='red'>Hello how are you ?</font>");
((EditText)v).setText(Html.fromHtml(str), TextView.BufferType.SPANNABLE);
}
}
}
});
[Edit 1]
yourEditText.setOnFocusChangedListener(new OnFocusChangedListener(){
@Override
public void onFocusChange(View v, boolean hasFocus){
if (hasFocus){
// But the words in an ArrayList then use them
for(String s : arrLst){
if (str.contains(s) == true) {
str = ((EditText)v)getText.ToString().replaceAll(s, "<font color='red'>Hello how are you ?</font>");
((EditText)v).setText(Html.fromHtml(str), TextView.BufferType.SPANNABLE); }
}
}
}
});
[Редактировать 2]
yourEditText.setOnFocusChangedListener(new OnFocusChangedListener(){
@Override
public void onFocusChange(View v, boolean hasFocus){
if (hasFocus){
int sSelection = ((EditText)v)getText.ToString().getSelectionStart();
int eSelection = ((EditText)v)getText.ToString().getSelectionEnd();
String sString = string.substring(sSelection, eSelection);
str = ((EditText)v)getText.ToString().replaceAll(sString , "<font color='red'>"+sString +"</font>");
((EditText)v).setText(Html.fromHtml(str), TextView.BufferType.SPANNABLE);
}
}
});
как я знаю selectedString о пользователе? –
int startSelection = et.getSelectionStart(); int endSelection = et.getSelectionEnd(); Строка selectedString = string.substring (startSelection, endSelection); Вы можете непосредственно: ул = "FONT COLOR = \" RED \ ">" + yourString «; textDisplayedBottom.setText (Html.fromHtml (ул)); –