TextView tv = (TextView) findViewById(R.id.abc);
String rawString = "abcdefg";
SpannableStringBuilder ssb = new SpannableStringBuilder(rawString);
ssb.setSpan(new StyleSpan(android.graphics.Typeface.BOLD), 0, rawString.length(), Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
tv.setText(ssb);
CharSequence cs = tv.getText();
System.out.println(cs.getClass());
输出是“类 android.text.SpannedString”
为什么?我希望它是“SpannableStringBuilder”,我的转换 ( SpannableStringBuilder ssb_2 = (SpannableStringBuilder)cs;
) 将在上面的示例中给出错误。
还有一些,如果我将文本视图的缓冲区类型设置为,输出将更改为“SpannableString”android:bufferType="spannable"
有谁知道为什么?