android.text.SpannableStringBuilder
public SpannableStringBuilder(CharSequence text) {
this(text, 0, text.length());
}
public SpannableStringBuilder append(CharSequence text) {
int length = length();
return replace(length, length, text, 0, text.length());
}
如果text为null会抛出NullPointerException
setSpan(Object what, int start, int end, int flags)中有一个checkRange(final String operation, int start, int end)方法
private void checkRange(final String operation, int start, int end) {
if (end < start) {
throw new IndexOutOfBoundsException(operation + " " +
region(start, end) + " has end before start");
}
int len = length();
if (start > len || end > len) {
throw new IndexOutOfBoundsException(operation + " " +
region(start, end) + " ends beyond length " + len);
}
if (start < 0 || end < 0) {
throw new IndexOutOfBoundsException(operation + " " +
region(start, end) + " starts before 0");
}
}
应该对传入的start和end做判断,不然容易抛出异常