在 Kindle Fire 上使用 TextAppearanceSpan 时出现奇怪的行为
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);
有其他人看到过这个,或者看到描述添加跨度规则的文档吗???
谢谢,-马克
Kindle Fire seems to have a 'different' way of handling spans in the SpannableStringBuilder. I found that when I add a TextAppearanceSpan before a ForegroundColorSpan the foreground color is ignored. If I add the TextAppearanceSpan first, then the ForegroundColorSpan it works fine. I have not seen this behavior on other Gingerbread devices, nor on Honeycomb devices...
FAILS:
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);
WORKS:
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);
Has anyone else seen this, or seen docs that describe rules for adding spans???
Thanks, - marc
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论