在AppWidgetPRovider中从未调用过ReplacementSpan绘制

时间:2018-12-13 11:15:43

标签: android android-appwidget

我的背景色范围是:

public class PaddingBackgroundColorSpan implements LineBackgroundSpan {

    private int mBackgroundColor;
    private int mPadding;
    private Rect mBgRect;

    public PaddingBackgroundColorSpan(int backgroundColor, int padding) {
        super();
        mBackgroundColor = backgroundColor;
        mPadding = padding;
        // Precreate rect for performance
        mBgRect = new Rect();
    }

    @Override
    public void drawBackground(Canvas c, Paint p, int left, int right, int top, int baseline, int bottom, CharSequence text, int start, int end, int lnum) {
        final int textWidth = Math.round(p.measureText(text, start, end));
        final int paintColor = p.getColor();
        // Draw the background
        mBgRect.set(left - mPadding,
                top - (lnum == 0 ? mPadding / 2 : - (mPadding / 2)),
                left + textWidth + mPadding,
                bottom + mPadding / 2);

        Logger.E("draw", mBgRect);

        p.setColor(mBackgroundColor);
        c.drawRect(mBgRect, p);
        p.setColor(paintColor);
    }
}

我的textviewandroid:bufferType="spannable"

我的问题是drawBackground从未调用过。

我也尝试过使用ReplacementSpan,但是使用draw时也是如此

否则,简单的BackgroundColorSpan工作正常...

任何帮助为什么draw方法从未在我的自定义范围中调用?

0 个答案:

没有答案