在Kindle Fire上使用TextAppearanceSpan的奇怪行为

时间:2011-11-30 21:33:46

标签: android kindle kindle-fire

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);

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);

有没有其他人看过这个,或者看过描述添加跨度的规则的文档???

谢谢, - marc

0 个答案:

没有答案