このコードを使用して、スパン可能なテキストのフォーマットを最初から最後まで削除しています。問題は、正常に機能していることですが、テキストの最後の文字がまだ太字 (または斜体/下線) になっていることです。
removeSpan
テキストの最後の文字で機能していません:
int startSelection = 0;
int endSelection = text.length();
if(startSelection > endSelection) {
startSelection = text.getSelectionEnd();
endSelection = text.getSelectionStart();
}
Spannable str = text.getText();
StyleSpan[] ss = str.getSpans(startSelection, endSelection, StyleSpan.class);
for (int i = 0; i < ss.length; i++) {
if (ss[i].getStyle() == android.graphics.Typeface.BOLD) {
str.removeSpan(ss[i]);
}
if (ss[i].getStyle() == android.graphics.Typeface.ITALIC) {
str.removeSpan(ss[i]);
}
}
UnderlineSpan[] ulSpan = str.getSpans(startSelection, endSelection, UnderlineSpan.class);
for (int i = 0; i < ulSpan.length; i++) {
str.removeSpan(ulSpan[i]);
}
str.removeSpan(ss[1]);
text.setText(str);