支持多个span的TextView:SpannableTextView

yg3n 9年前

可接受一个或多个span的TextView。它支持以下spans:

ForegroundColorSpanBackgroundColorSpanCustomTypefaceSpanRelativeSizeSpanURLSpanUnderlineSpanStrikethroughSpanQuoteSpanSubscriptSpanSuperscriptSpan

SpannableTextView

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);

项目主页:http://www.open-open.com/lib/view/home/1433386386838