Why doesn't my text show up with style when using SpannableStringBuilder?

后端 未结 4 1596
清酒与你
清酒与你 2020-12-10 07:16

I have a problem with a SpannableString object.

Below\'s a short example:

SpannableString spanstr = new SpannableString(\"Bold please!\"         


        
4条回答
  •  孤街浪徒
    2020-12-10 07:33

    Use the spannable string builder for setting as text in textview :

    contentView.setText(sb);
    

    or else you can do like this :

    SpannableStringBuilder spanstr = new SpannableStringBuilder("Bold please!");
    spanstr.setSpan(new StyleSpan(Typeface.BOLD), 0, spanstr.length(), Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
    spanstr.append("\n");
    spanstr.append("The first line is bold. This one isn't.");
    contentView.setText(spanstr);
    

提交回复
热议问题