EditText Style Word

April 14 2013
This example shows how you can make a word bold, italic, underline, and blue in a EditText using Spans. StyleWord.zip
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.

Leave a Reply

Your email address will not be published. Required fields are marked *