I need to create a String placed in a TextView that will display a string like this:
First Part Not Bold BOLD rest not bold
>
From API 21 SpannableStringBuilder includes a simple method to do this. Here is a solution example:
SpannableStringBuilder builder= new SpannableStringBuilder();
StyleSpan boldSpan = new StyleSpan(android.graphics.Typeface.BOLD);
builder.append("First Part Not Bold ")
.append("BOLD ", boldSpan, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE)
.append("rest not bold");
Since it is a good chance you do not support API 21 only you can duplicate the code from that method:
public SpannableStringBuilder append(CharSequence text, Object what, int flags) {
int start = length();
append(text);
setSpan(what, start, length(), flags);
return this;
}