Strange behavior using TextAppearanceSpan on Kindle Fire

Kindle Fire seems to have a “different” way of handling intervals in the SpannableStringBuilder. I found that when I add a TextAppearanceSpan in front of ForegroundColorSpan, the foreground color is ignored. If I add TextAppearanceSpan first, then ForegroundColorSpan works fine. I have not seen this behavior on other Gingerbread devices or on cellular 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 documents describing the rules for adding intervals ???

Thanks, - marc

+4
source share

Source: https://habr.com/ru/post/1383992/


All Articles