How to create rounded corners in background of multiline text, where lines have different width

Viewed 406

I need to make background color of text in EditText like in the picture.

Making corners rounded and paddings is quite easy with custom LineBackgroundSpan. I implemented it like this:

class RoundedCornersBackgroundSpan(val padding: Int,
                               val backgroundColor: Int) : LineBackgroundSpan {

val backgroundRect = Rect()

override fun drawBackground(c: Canvas, p: Paint, left: Int, right: Int, top: Int, baseline: Int, bottom: Int, text: CharSequence?, start: Int, end: Int, lnum: Int) {
    if(text == null) return
    val textWidth = Math.round(p.measureText(text, start, end))
    val paintColor = p.color
    backgroundRect.set(left - padding,
            top - if(lnum == 0) { padding / 2 } else { - (padding / 2 ) },
            left + textWidth + padding,
            bottom + (padding / 2))
    p.color = backgroundColor
    c.drawRoundRect(RectF(backgroundRect), 3.fromDpToPixelsF(), 3.fromDpToPixelsF(), p)
    p.color = paintColor
}}

But how can I implement this "inner" corners, which annotated with arrows in the picture? picture with desired effect

1 Answers
Related