0

我正在写一个RichTextEditor类,它有一个内部RichTextEditorTextWatcher类。我看到的与我在屏幕上看到的不同,与我在e.getSpans里面打电话时得到的不同beforeTextChanged

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

这是一个已知的 Android 错误吗?

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;
        }
    }
}
4

0 回答 0