title: Is it possible to have multiple styles inside a TextView?
body: <p>Is it possible to set multiple styles for different pieces of text inside a TextView?</p>
  
  <p>For instance, I am setting the text as follows:</p>
  
  <pre><code>tv.setText(line1 + "\n" + line2 + "\n" + word1 + "\t" + word2 + "\t" + word3);
  </code></pre>
  
  <p>Is it possible to have a different style for each text element? E.g., line1 bold, word1 italic, etc.</p>
  
  <p>The developer guide's <a href="http://developer.android.com/guide/faq/commontasks.html" rel="noreferrer">Common Tasks and How to Do Them in Android</a> includes <a href="http://developer.android.com/guide/faq/commontasks.html#selectingtext" rel="noreferrer">Selecting, Highlighting, or Styling Portions of Text</a>:</p>
  
  <blockquote>
  <pre><code>// Get our EditText object.
  EditText vw = (EditText)findViewById(R.id.text);
  
  // Set the EditText's text.
  vw.setText("Italic, highlighted, bold.");
  
  // If this were just a TextView, we could do:
  // vw.setText("Italic, highlighted, bold.", TextView.BufferType.SPANNABLE);
  // to force it to use Spannable storage so styles can be attached.
  // Or we could specify that in the XML.
  
  // Get the EditText's internal text storage
  Spannable str = vw.getText();
  
  // Create our span sections, and assign a format to each.
  str.setSpan(new StyleSpan(android.graphics.Typeface.ITALIC), 0, 7, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
  str.setSpan(new BackgroundColorSpan(0xFFFFFF00), 8, 19, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
  str.setSpan(new StyleSpan(android.graphics.Typeface.BOLD), 21, str.length() - 1, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
  </code></pre>
  </blockquote>
  
  <p>But that uses explicit position numbers inside the text. Is there a cleaner way to do this?</p>