SpannableString text = new SpannableString("RAHUL");
text.setSpan(new ForegroundColorSpan(white), 0, 2, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
text.setSpan(new ForegroundColorSpan(blue), 3, 4, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
headerHolder.mTextViewLabel.setText(text, TextView.BufferType.SPANNABLE);
我只得到“HL”作为输出。
最佳答案
通过输出检查这一点
SpannableString text = new SpannableString("RAHUL");
text.setSpan(new ForegroundColorSpan(Color.WHITE), 0, 3, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
text.setSpan(new ForegroundColorSpan(Color.BLUE), 3, 5, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
tv.setText(text);
棉花糖输出
希望对你有帮助
关于android - 我正在尝试在 Marshamallow 上使用 spannable。它给了我不正确的输出,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37916744/