I set the following text and style in my EditText:
SpannableStringBuilder sb = new SpannableStringBuilder();
sb.append("Hello");
sb.setSpan(new StyleSpan(Typeface.BOLD), 0, 5, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
sb.append("World Test");
et.setText(sb);
The result is this: "HelloWorld Test". This is fine. Now when I position the cursor after the "d" character (i.e. before the space that separates World and Test) and enter a character, the Hello automatically loses its bold style.
Why is that? That is confusing me. It only happens when positioning the cursor directly after the "d" in World and entering a character. For all other cursor positions it works as expected.
Why is that and how to fix it? I want Hello to stay in bold.
may be you should try this
or try this after api 21
like html style try below