Is it possible to set multiple styles for different pieces of text inside a TextView?
For instance, I am setting the text as follows:
tv.setText(line
Using an auxiliary Spannable Class as Android String Resources shares at the bottom of the webpage. You can approach this by creatingCharSquences
and giving them a style.
But in the example they give us, is just for bold, italic, and even colorize text. I needed to wrap several styles in aCharSequence
in order to set them in a TextView
. So to that Class (I named it CharSequenceStyles
) I just added this function.
public static CharSequence applyGroup(LinkedList content){
SpannableStringBuilder text = new SpannableStringBuilder();
for (CharSequence item : content) {
text.append(item);
}
return text;
}
And in the view I added this.
message.push(postMessageText);
message.push(limitDebtAmount);
message.push(pretMessageText);
TextView.setText(CharSequenceStyles.applyGroup(message));
I hope this help you!