Scheming with the Coco and Android

April 14 2013
This example shows how you can make a word bold, italic, underline, and blue in a EditText using Spans.
From layout xml:

<EditText android:id="@+id/editText"
  android:layout_height="wrap_content" />

from src java:

Spannable spannable=new SpannableString(string);
spannable.setSpan(new StyleSpan(Typeface.BOLD), start, end, 0);
spannable.setSpan(new StyleSpan(Typeface.ITALIC), start, end, 0);
spannable.setSpan(new UnderlineSpan(), start, end, 0);
spannable.setSpan(new ForegroundColorSpan(Color.BLUE), start, end, 0);

Spannable.SPAN_EXCLUSIVE_EXCLUSIVE is the 0 at the end of the setSpan parameter lists.

§487 · By · March 1, 2013 ·

Leave a Reply