以下代码适用于我在 2.3 和 6.0.1 之间尝试的所有内容,但在 7.0/Emulator 和 7.1.1/Nexus 6P 中失败
SpannableStringBuilder spannableStringBuilder = new SpannableStringBuilder();
for (int i=0;i<5;++i) {
int p = spannableStringBuilder.length();
spannableStringBuilder.append("aAAAAa\n");
spannableStringBuilder.setSpan(new StyleSpan(Typeface.ITALIC), p+1, p+5, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
}
boolean pass = true;
StyleSpan[] spans = spannableStringBuilder.getSpans(0, spannableStringBuilder.length(), StyleSpan.class);
int p = 0;
for (StyleSpan span : spans) {
int start = spannableStringBuilder.getSpanStart(span);
if (start<p) {
pass = false;
break;
}
p = start;
}