Kindle Fire 似乎在 SpannableStringBuilder 中有一种“不同”的处理跨度的方式。我发现当我在 ForegroundColorSpan之前添加一个 TextAppearanceSpan 时,前景色被忽略了。如果我先添加 TextAppearanceSpan,然后 ForegroundColorSpan 它工作正常。我没有在其他 Gingerbread 设备和 Honeycomb 设备上看到这种行为......
失败:
String text = "Styled with TextAppearanceSpan then ForegroundColor";
int textLen = text.length();
CharSequence styledText = "";
SpannableStringBuilder ssb = new SpannableStringBuilder(text);
ssb.setSpan(new TextAppearanceSpan(null, 0, 32, null, null), 0, textLen, 0);
ssb.setSpan(new ForegroundColorSpan(0xFFFF0000), 0, textLen, 0);
styledText = TextUtils.concat(styledText, ssb);
tv2.setText(styledText);
作品:
String text = "Styled with ForegroundColor then TextAppearanceSpan";
int textLen = text.length();
CharSequence styledText = "";
SpannableStringBuilder ssb = new SpannableStringBuilder(text);
ssb.setSpan(new ForegroundColorSpan(0xFFFF0000), 0, textLen, 0);
ssb.setSpan(new TextAppearanceSpan(null, 0, 32, null, null), 0, textLen, 0);
styledText = TextUtils.concat(styledText, ssb);
tv1.setText(styledText);
有没有其他人看过这个,或者看过描述添加跨度规则的文档???
谢谢,-马克