Added in API level 34

Builder


class Builder
kotlin.Any
   ↳ android.text.Highlights.Builder

A builder for the Highlights.

Summary

Public constructors

Public methods
Highlights.Builder
addRange(paint: Paint, start: Int, end: Int)

Add single range highlight.

Highlights.Builder
addRanges(paint: Paint, vararg ranges: Int)

Add multiple ranges highlight.

Highlights

Build a new Highlights instance.

Public constructors

Builder

Builder()

Public methods

addRange

Added in API level 34
fun addRange(
    paint: Paint,
    start: Int,
    end: Int
): Highlights.Builder

Add single range highlight. The android.widget.TextView and underlying Layout draws highlight in the order of the addRange calls. For example, the following code draws (1, 2) with red and (2, 5) with blue. val redPaint = Paint().apply { color = Color.RED } val bluePaint = Paint().apply { color = Color.BLUE } val highlight = Highlights.Builder() .addRange(redPaint, 1, 4) .addRange(bluePaint, 2, 5) .build()

Parameters
paint Paint: a paint object used for drawing highlight path.
start Int: an inclusive offset of the text.
end Int: an exclusive offset of the text.
Return
Highlights.Builder this builder instance.

addRanges

Added in API level 34
fun addRanges(
    paint: Paint,
    vararg ranges: Int
): Highlights.Builder

Add multiple ranges highlight. For example, the following code draws (1, 2) with red and (2, 5) with blue. val redPaint = Paint().apply { color = Color.RED } val bluePaint = Paint().apply { color = Color.BLUE } val highlight = Highlights.Builder() .addRange(redPaint, 1, 4) .addRange(bluePaint, 2, 5) .build()

Parameters
paint Paint: a paint object used for drawing highlight path.
ranges Int: a flatten ranges. The 2 * i-th element is an inclusive start offset of the i-th character. The 2 * i + 1-th element is an exclusive end offset of the i-th character.
Return
Highlights.Builder this builder instance.

build

Added in API level 34
fun build(): Highlights

Build a new Highlights instance.

Return
Highlights a new Highlights instance.