我的背景色范围是:
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);
}
}
我的textview
在android:bufferType="spannable"
我的问题是drawBackground
从未调用过。
我也尝试过使用ReplacementSpan
,但是使用draw
时也是如此
否则,简单的BackgroundColorSpan
工作正常...
任何帮助为什么draw方法从未在我的自定义范围中调用?