title: How to apply styles from styles.xml to span?
body: <p>I'm trying to apply a custom style defined in styles.xml to part of a string in a <code>TextView</code>. I tried using <code>SpannableStringBuilder</code> with <code>StyleSpan</code>, but that doesn't seem to work. Would appreciate any pointers on this. Here's what my code looks like right now:</p>
  
  <p>styles.xml</p>
  
  <pre><code>&lt;style name="damn_red"&gt;
       &lt;item name="android:textColor"&gt;@color/f_red_800&lt;/item&gt;
       &lt;item name="android:background"&gt;@color/f_red_800&lt;/item&gt;
       &lt;item name="android:text"&gt;@color/f_red_800&lt;/item&gt;
  &lt;/style&gt;
  </code></pre>
  
  <p>Activity.java</p>
  
  <pre><code>SpannableStringBuilder spannable = new SpannableStringBuilder();
  spannable.append("Some ")
           .append("text ",  new StyleSpan(R.style.damn_red), Spanned.SPAN_INCLUSIVE_INCLUSIVE)
           .append("this is");
  TextView textView = findViewById(R.id.mytextview);
  textView.setText(spannable, TextView.BufferType.SPANNABLE);
  </code></pre>
  
  <p>I've looked at multiple questions here but couldn't find any that would answer this. Would appreciate any pointers here. Thanks!</p>