How to set italic typeface for future text in current cursor position on edittext and to bring it back to normal?

1

I want to apply Text Format Options on Edittext. I am able to apply Bold, Italic, Strike, Underline after spacebar is trigger but i can't bring it back to normal typeface. I want to apply this typeface on the current cursor position, also able to bring it back to normal typeface.

i am using Sketchware App.

here's my code:

if (editText_is_Italic) {
editText_is_Italic = false; btn_italic.setColorFilter(0xFFFFFFFF, PorterDuff.Mode.MULTIPLY);
StyleSpan Spantxt = new StyleSpan(Typeface.NORMAL);
int start = edittext2.getSelectionStart();
int end = edittext2.getSelectionEnd();
int flag = Spannable.SPAN_INCLUSIVE_INCLUSIVE;
edittext2.getText().setSpan(Spantxt, start, end, flag);
}
else {
if (!editText_is_Italic) {

    editText_is_Italic = true;
    btn_italic.setColorFilter(0xFFFFC107, PorterDuff.Mode.MULTIPLY);
    StyleSpan Spantxt = new StyleSpan(Typeface.ITALIC);
    int start = edittext2.getSelectionStart();
    int end = edittext2.getSelectionEnd();
    int flag = Spannable.SPAN_INCLUSIVE_INCLUSIVE;
    edittext2.getText().setSpan(Spantxt, start, end, flag);
}
}

I've try to use .removeSpan(); and .clearSpans(); on removing span, also i've try Spannable.SPAN_EXCLUSIVE_INCLUSIVE to set this on current cursor position. But no one succed.

java
android
spannable
sketchware
asked on Stack Overflow Oct 21, 2020 by RJA programer • edited Oct 21, 2020 by RJA programer

0 Answers

Nobody has answered this question yet.


User contributions licensed under CC BY-SA 3.0