This is example.
String source = "This is example text";
Spannable out = new SpannedString(source);
StyleSpan boldSpan = new StyleSpan(Typeface.BOLD);
out.setSpan(boldSpan, 1, 3, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
out.setSpan(boldSpan, 9, 12, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
//someTextView.setText(out);
Expected result: This is example text ("hi" & "xam" are bold)
Actual result: This is example text (works only last setSpan method and bold is only "xam")
How to make multi spannable text? It's possible?
Maybe problem is in Spannable.SPAN_EXCLUSIVE_EXCLUSIVE flag? Thanks.
I think you need a new StyleSpan for each.
String source = "This is example text";
Spannable out = new SpannedString(source);
StyleSpan boldSpan = new StyleSpan(Typeface.BOLD);
StyleSpan boldSpan2 = new StyleSpan(Typeface.BOLD);
out.setSpan(boldSpan, 1, 3, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
out.setSpan(boldSpan2, 9, 12, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
Haven't tried it out though.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With