SpannableStringBuilder not working in TextView Android

785 views Asked by At

I am stuck while setting the text color of a word in TextView.

Below is my code :

     final SpannableStringBuilder sb = new SpannableStringBuilder(first + next);

    // Span to set text color to some RGB value
final ForegroundColorSpan fcs = new ForegroundColorSpan(Color.rgb(0,0,255));

    // Span to make text bold
 final StyleSpan bss = new StyleSpan(android.graphics.Typeface.BOLD);

    // Set the text color for first 4 characters
sb.setSpan(fcs, 0, first.length(), Spannable.SPAN_INCLUSIVE_INCLUSIVE);

    // make them also bold
 sb.setSpan(bss, 0, first.length(), Spannable.SPAN_INCLUSIVE_INCLUSIVE);
  textView.setText(sb);

Here is the XML of TextView -

    <TextView
        android:id="@+id/comment_first"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_gravity="center_vertical"
        android:layout_marginLeft="5dp"
        android:ellipsize="end"
        android:maxLines="5"
        android:textAllCaps="false"
        android:text="Lorem Ipsum is simply dummy text"
        android:textSize="@dimen/description_text" />

My Tries -

  1. Set this but no results.

    android:textAllCaps="false"

0

There are 0 answers