I set background in string like that:
spanString.setSpan(new BackgroundColorSpan(color), 0, 3, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
But I would l
The documentation for ReplacementSpan.getSize() provides the answer:
Returns the width of the span. Extending classes can set the height of the span by updating attributes of Paint.FontMetricsInt. If the span covers the whole text, and the height is not set, draw() will not be called for the span.
Make sure to update Paint.FontMetricsInt
with proper values to fix the problem.
In my case, I just took the metrics from the TextView
's Paint
:
@Override
public int getSize(
Paint paint,
CharSequence text,
int start,
int end,
Paint.FontMetricsInt fm) {
final Paint.FontMetrics paintFontMetrics = paint.getFontMetrics();
if (fm != null) {
fm.ascent = (int) paintFontMetrics.ascent;
fm.bottom = (int) paintFontMetrics.bottom;
fm.descent = (int) paintFontMetrics.descent;
fm.leading = (int) paintFontMetrics.leading;
fm.top = (int) paintFontMetrics.top;
}
//...
}