Android Edittext- Clearing Spans
Had the same problem. Solved it by removing only the types of spans that I added to the EditText. I guess clearSpans removes more than it should. I did something like this for each type of span I used:
toRemoveSpans = et.getSpans(0, et.getText().length(), ForegroundColorSpan.class);
for (int i = 0; i < toRemoveSpans.length; i++)
et.removeSpan(toRemoveSpans[i]);
private void clearSpans(@NonNull final Editable editable) {
final Object[] spans = editable.getSpans(0, editable.length(), Object.class);
for (final Object span : spans) {
if (span instanceof ForegroundColorSpan || span instanceof SpannableTextView.CustomTypefaceSpan) {
editable.removeSpan(span);
}
}
}
Depending on type of spans you have added you may have to include more than just ForegroundColorSpan. The above method is a simple drop in replacement and it easy to specify what spans to remove.