Sitemap
Joe

Joe

Member-only story

Android Spannable String example

2 min readMar 22, 2019

SpannableString in android is an excellent way to style strings in a TextView.

Not a member ? Read this story for free here

Put simply, it allows a TextView to have different styles to different areas of text.

In the following example, we create in Activity to display a single TextView.

The TextView will use a SpannableString as its content, which will illustrate some of the available styles.

Here’ what we’re gonna do with the text :

  • Make it larger
  • Bold
  • Underline
  • Italicize
  • Strike-through
  • Colored
  • Highlighted
  • Show as superscript
  • Show as subscript
  • Show as a link
  • Make it clickable.

The finished Activity will look like this :

So lets’s dig in :). For simplicity, I’ve limited myself to the onCreate() method of the Activity.

--

--