0

我在谷歌文档中阅读了 flags 参数,但我找不到它到底在做什么。例如在下面的代码中:

SpannableStringBuilder builder1 = new SpannableStringBuilder();
builder1.append("hi");
builder1.append("this is test");
builder1.setSpan(new ForegroundColorSpan(Color.RED), 0, 7, Spanned.SPAN_INCLUSIVE_EXCLUSIVE);
myTextView.setText(builder1);

如果您更改第 4 个参数并设置如下变量,则没有区别:Spanned.SPAN_INCLUSIVE_INCLUSIVE,Spanned.SPAN_INCLUSIVE_EXCLUSIVE,Spanned.SPAN_EXCLUSIVE_EXCLUSIVE,Spanned.SPAN_EXCLUSIVE_EXCLUSIVE。

结果没有区别。

但是当运行这段代码时:

SpannableStringBuilder builder1 = new SpannableStringBuilder();
builder1.append("hi");
builder1.append("this is test");
builder1.setSpan(new ForegroundColorSpan(Color.RED), 0, 7, Spanned.SPAN_INCLUSIVE_EXCLUSIVE);

SpannableStringBuilder builder2 = new SpannableStringBuilder();
builder1.append("second test this is going to be different");
builder1.setSpan(new BackgroundColorSpan(Color.BLUE), 10, 15, Spanned.SPAN_INCLUSIVE_EXCLUSIVE);

SpannableStringBuilder all = new SpannableStringBuilder();
all.append(builder2);
all.insert(0, "\n");
all.insert(0, builder1);

根据传递给 builder1.setSpan 的第四个参数,您会得到不同的结果

有人可以解释为什么会这样吗?

4

1 回答 1

0

该标志设置在用于在输入法的组成文本上应用临时样式信息的跨度上,以便在替换组成文本时可以找到并删除它们

于 2016-12-19T10:53:26.990 回答