0

在此处输入图像描述

我想用 ImageSpan 突出显示 EditText 的一部分,但 BackgroundSpan 对 ImageSpan 没有影响。我想到了函数:setSelection。我想突出显示 EditText 但不选择。

我想我可以从 setSelection 的源代码中学习,有人可以帮助我或提供 setSelection 的源代码吗?在此处输入图像描述

4

1 回答 1

0

这些是源代码

  /**
     * Set the selection anchor to <code>start</code> and the selection edge
     * to <code>stop</code>.
     */
    public static void setSelection(Spannable text, int start, int stop) {
        // int len = text.length();
        // start = pin(start, 0, len);  XXX remove unless we really need it
        // stop = pin(stop, 0, len);

        int ostart = getSelectionStart(text);
        int oend = getSelectionEnd(text);

        if (ostart != start || oend != stop) {
            text.setSpan(SELECTION_START, start, start,
                         Spanned.SPAN_POINT_POINT|Spanned.SPAN_INTERMEDIATE);
            text.setSpan(SELECTION_END, stop, stop,
                         Spanned.SPAN_POINT_POINT);
        }
    }



   /**
     * Move the cursor to offset <code>index</code>.
     */
    public static final void setSelection(Spannable text, int index) {
        setSelection(text, index, index);
    }

在此处查看完整来源

于 2013-05-31T03:30:08.573 回答