Android editable.getSpans返回一个StyleSpan,即使没有';屏幕上没有呈现任何样式

Android editable.getSpans返回一个StyleSpan,即使没有';屏幕上没有呈现任何样式,android,android-edittext,android-textwatcher,Android,Android Edittext,Android Textwatcher,我正在编写一个RichTextEditor类,它有一个内部RichTextEditorTextWatcher类。我看到屏幕上显示的内容与调用e.getspaninternalbeforetextchange时得到的内容不一致 在屏幕上,我看到屏幕上的文本(在我的例子中,是单个字符)没有应用任何样式,但是e.getspan()调用实际上表明我应用了粗体样式 这是一个已知的安卓bug吗 public class RichTextEditor extends AppCompatEditText {

我正在编写一个
RichTextEditor
类,它有一个内部
RichTextEditorTextWatcher
类。我看到屏幕上显示的内容与调用
e.getspan
internal
beforetextchange
时得到的内容不一致

在屏幕上,我看到屏幕上的文本(在我的例子中,是单个字符)没有应用任何样式,但是
e.getspan()
调用实际上表明我应用了粗体样式

这是一个已知的安卓bug吗

public class RichTextEditor extends AppCompatEditText  
{

    // other code not shown

    public class RichTextEditorTextWatcher implements TextWatcher
    {
        @Override
        public void beforeTextChanged(CharSequence s, int start, int count, int after)
        {
            if (after == 0) //deletion occurred
            {
                isDeletion = true;
                Editable e = RichTextEditor.this.getText();

                /** The next line is the problematic line!
                  * this.prevStyles returns a StyleSpan (bold) even when I don't see it on the screen for that character.
                  */
                this.prevStyles = e.getSpans(start, start+count, CharacterStyle.class); 

                for (CharacterStyle c : this.prevStyles)
                {
                    if (c instanceof StyleSpan)
                    {
                        if (((StyleSpan)c).getStyle() == Typeface.BOLD) 
                            boldButton.setChecked(true);
                        else
                            boldButton.setChecked(false);
                    }
                }
            }
            else
                isDeletion = false;
        }
    }
}

TextUtils#dumpspan()
说什么?嘿@pskink。我现在正在使用
TextUtils#dumpspan()
,它很有用!似乎我需要执行
e.removeSpan(currSpan)
并将其应用于缩短的(带删除的)跨度,因为跨度持续存在。我不知道你的意思,但是,嘿,很好,这很有帮助!