Protected void onCreate (Bundle savedInstanceState ){
Super. onCreate (savedInstanceState );
SetContentView (R. layout. textview );
TextView txtInfo = (TextView) findViewById (R. id. TV );
// SpannableString text class, which contains immutable text but can be replaced and separated with existing objects.
// For variable Text classes, refer to SpannableStringBuilder.
SpannableString ss = new SpannableString ("red phone italic strikethrough green underline image :.");
// Mark text with color
Ss. setSpan (new ForegroundColorSpan (Color. RED), 0, 2,
// The flag to be specified during setSpan, Spanned. SPAN_EXCLUSIVE_EXCLUSIVE (not included before and after ).
Spanned. SPAN_EXCLUSIVE_EXCLUSIVE );
// Mark text with hyperlink
Ss. setSpan (new URLSpan ("tel: 4155551212"), 2, 5,
Spanned. SPAN_EXCLUSIVE_EXCLUSIVE );
// Mark text with style (italic)
Ss. setSpan (new StyleSpan (Typeface. BOLD_ITALIC), 5, 7,
Spanned. SPAN_EXCLUSIVE_EXCLUSIVE );
// Mark text with strikethrough
Ss. setSpan (new StrikethroughSpan (), 7, 10,
Spanned. SPAN_EXCLUSIVE_EXCLUSIVE );
// Mark the text with underscores
Ss. setSpan (new UnderlineSpan (), 10, 16,
Spanned. SPAN_EXCLUSIVE_EXCLUSIVE );
// Mark with color
Ss. setSpan (new ForegroundColorSpan (Color. GREEN), 10, 13,
Spanned. SPAN_EXCLUSIVE_EXCLUSIVE );
// Obtain the Drawable Resource
Drawable d = getResources (). getDrawable (R. drawable. icon );
D. setBounds (0, 0, d. getIntrinsicWidth (), d. getIntrinsicHeight ());
// Create ImageSpan
ImageSpan span = new ImageSpan (d, ImageSpan. ALIGN_BASELINE );
// Replace text with ImageSpan
Ss. setSpan (span, 18, 19, Spannable. SPAN_INCLUSIVE_EXCLUSIVE );
TxtInfo. setText (ss );
TxtInfo. setMovementMethod (LinkMovementMethod. getInstance (); // implement text scrolling.
}
: