如何检测TextView是否包含SpannableStringBuilder

时间:2015-03-29 05:44:47

标签: android textview spannablestring

如何判断TextView是否包含SpannableStringBuilder而不是纯文本? 我需要更改TextView的文字大小,但如果它包含纯文本或跨度则会有所不同。

TextView textView1;
textView1.setText("BlahBlahBlah");

TextView textView2;
final SpannableStringBuilder sb = new SpannableStringBuilder(title);
                                                        final ForegroundColorSpan fcs = new ForegroundColorSpan(Color.rgb(255,255,255));
                                                        sb.setSpan(fcs,  bookname.length(),title.length(), Spannable.SPAN_INCLUSIVE_INCLUSIVE);
textView2.setText(sb);

现在我需要一个像这样的方法: textView1.hasSpans()

1 个答案:

答案 0 :(得分:3)

使用instanceOf

 final CharSequence text = textView.getText();
 if(text instanceof Spannable){
    ...

我在setFilter中使用它,所以没有理由不在这里工作

相关问题