I have a custom span, its superclass is LineBackgroundSpan
.
class CustomUnderlineSpan(
private val underlineDrawable: Drawable
) : LineBackgroundSpan {
override fun drawBackground(
canvas: Canvas,
paint: Paint,
left: Int,
right: Int,
top: Int,
baseline: Int,
bottom: Int,
text: CharSequence,
start: Int,
end: Int,
lineNumber: Int
) {
// For some devices this method is not always called
underlineDrawable.draw(canvas)
}
}
I'm creating span like this:
SpannableString(fullText).apply {
setSpan(
CustomUnderlineSpan(bodyState.drawable),
fullText.indexOf(phrase),
fullText.indexOf(phrase) + phrase.length,
Spannable.SPAN_EXCLUSIVE_EXCLUSIVE
)
}
For some devices the drawBackground
method of some spans is not called.
What could be the reason?