If the user enters the text in EditText , and it contains the substring "more", then it should be highlighted in red.
Advise how to properly implement and what is required for this.
If the user enters the text in EditText , and it contains the substring "more", then it should be highlighted in red.
Advise how to properly implement and what is required for this.
editText.addTextChangedListener(new TextWatcher() { @Override public void beforeTextChanged(CharSequence s, int start, int count, int after) {} @Override public void onTextChanged(CharSequence s, int start, int before, int count) { String str = "more"; Spannable spannable = editText.getText(); if(s.length() != 0) { editText.setTextColor(Color.parseColor("#000000")); //весь текст черным ForegroundColorSpan fcs = new ForegroundColorSpan(Color.RED); // красим в красный, если найдется more String s1 = s.toString(); int in = 0; while ((in = s1.indexOf(str, in)) >= 0) { spannable.setSpan(fcs, in, in + str.length(), Spannable.SPAN_EXCLUSIVE_EXCLUSIVE); in += str.length(); } } } @Override public void afterTextChanged(Editable s) {} }); //постоянный мониторинг для EditText'а Source: https://ru.stackoverflow.com/questions/733824/
All Articles