Q:

onTextChanged function does not work correctly in saving edittext colors

I am trying to save edit text with different colors dynamically but when I save it by converting it into HTML form it only saves the text in one color and not in the colors that I selected.
Here is the Textchanged, str is the spannable text.
text.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) {

                if(start < s.length() - 1 || count > before){
                    str.setSpan(new ForegroundColorSpan(Color.parseColor(txtColor)), start,start+1 , Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
                }
            }
            @Override
            public void afterTextChanged(Editable s) {

            }
        });

A:

try this in your after text changes and it will solve your problem.
public void afterTextChanged(Editable s) {
        str.removeSpan(new ForegroundColorSpan(Color.parseColor(currentColor)));
       }

