支持多個span的TextView:SpannableTextView
可接受一個或多個span的TextView。它支持以下spans:
ForegroundColorSpanBackgroundColorSpanCustomTypefaceSpanRelativeSizeSpanURLSpanUnderlineSpanStrikethroughSpanQuoteSpanSubscriptSpanSuperscriptSpan
Sample Usage
// Setup single span
SpannableTextView tv1 = (SpannableTextView) view.findViewById(R.id.tv1);
Span span1 =
new Span.Builder("ForegroundSpan, BackgroundSpan, and CustomTypefaceSpan")
.foregroundColor(R.color.purple_500)
.backgroundColor(R.color.green_500)
.typeface(mItalicFont)
.build();
tv1.setFormattedText(span1);
// Setup multiple spans
SpannableTextView tv2 = (SpannableTextView) view.findViewById(R.id.tv2);
List<Span> spans1 = new ArrayList<>();
spans1.add(new Span.Builder("ForegroundSpan")
.foregroundColor(R.color.red_500)
.build());
spans1.add(new Span.Builder("BackgroundSpan")
.backgroundColor(R.color.yellow_500)
.build());
spans1.add(new Span.Builder("ForegroundSpan and BackgroundSpan")
.foregroundColor(R.color.orange_500)
.backgroundColor(R.color.blue_500)
.build());
spans1.add(new Span.Builder("ForegroundSpan, BackgroundSpan, and CustomTypefaceSpan")
.foregroundColor(R.color.green_500)
.backgroundColor(R.color.indigo_500)
.typeface(mRegularFont)
.build());
tv2.setFormattedText(spans1); 本文由用戶 yg3n 自行上傳分享,僅供網友學習交流。所有權歸原作者,若您的權利被侵害,請聯系管理員。
轉載本站原創文章,請注明出處,并保留原始鏈接、圖片水印。
本站是一個以用戶分享為主的開源技術平臺,歡迎各類分享!
