# Highlights.Builder

Added in[API level 34](https://developer.android.com/guide/topics/manifest/uses-sdk-element.html#ApiLevels)

# Builder

*** ** * ** ***

Kotlin\|[Java](https://developer.android.com/reference/android/text/Highlights.Builder "View this page in Java")  

```
class Builder
```

|---|--------------------------------------------------------------------------------------------------------------------|
| [kotlin.Any](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-any/index.html)                                     ||
| ↳ | [android.text.Highlights.Builder](https://developer.android.com/reference/kotlin/android/text/Highlights.Builder#) |

A builder for the Highlights.

## Summary

|                                                Public constructors                                                ||
|----------------------------------------------------------------------------------------------------------------|---|
| [Builder](https://developer.android.com/reference/kotlin/android/text/Highlights.Builder#Builder())`()` <br /> |

|                                                                                                                                                                                                                                                                              Public methods                                                                                                                                                                                                                                                                               ||
|-------------------------------------------------------------------------------------------------------|--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| [Highlights.Builder](https://developer.android.com/reference/kotlin/android/text/Highlights.Builder#) | [addRange](https://developer.android.com/reference/kotlin/android/text/Highlights.Builder#addRange(android.graphics.Paint,%20kotlin.Int,%20kotlin.Int))`(`paint:` `[Paint](https://developer.android.com/reference/kotlin/android/graphics/Paint.html#)`, `start:` `[Int](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-int/index.html)`, `end:` `[Int](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-int/index.html)`)` Add single range highlight. |
| [Highlights.Builder](https://developer.android.com/reference/kotlin/android/text/Highlights.Builder#) | [addRanges](https://developer.android.com/reference/kotlin/android/text/Highlights.Builder#addRanges(android.graphics.Paint,%20kotlin.Int))`(`paint:` `[Paint](https://developer.android.com/reference/kotlin/android/graphics/Paint.html#)`, `vararg` `ranges:` `[Int](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-int/index.html)`)` Add multiple ranges highlight.                                                                                     |
| [Highlights](https://developer.android.com/reference/kotlin/android/text/Highlights)                  | [build](https://developer.android.com/reference/kotlin/android/text/Highlights.Builder#build())`()` Build a new Highlights instance.                                                                                                                                                                                                                                                                                                                               |

## Public constructors

### Builder

```
Builder()
```

## Public methods

### addRange

Added in[API level 34](https://developer.android.com/guide/topics/manifest/uses-sdk-element.html#ApiLevels)  

```
fun addRange(
    paint: Paint, 
    start: Int, 
    end: Int
): Highlights.Builder
```

Add single range highlight. The[android.widget.TextView](https://developer.android.com/reference/kotlin/android/widget/TextView.html#)and underlying[Layout](https://developer.android.com/reference/kotlin/android/text/Layout)draws highlight in the order of the[addRange](https://developer.android.com/reference/kotlin/android/text/Highlights.Builder#addRange(android.graphics.Paint,%20kotlin.Int,%20kotlin.Int))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](https://developer.android.com/reference/kotlin/android/graphics/Paint.html#):a paint object used for drawing highlight path. |
| `start` | [Int](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-int/index.html):an inclusive offset of the text.                          |
| `end`   | [Int](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-int/index.html):an exclusive offset of the text.                          |

|                                                            Return                                                             ||
|-------------------------------------------------------------------------------------------------------|------------------------|
| [Highlights.Builder](https://developer.android.com/reference/kotlin/android/text/Highlights.Builder#) | this builder instance. |

### addRanges

Added in[API level 34](https://developer.android.com/guide/topics/manifest/uses-sdk-element.html#ApiLevels)  

```
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](https://developer.android.com/reference/kotlin/android/graphics/Paint.html#):a paint object used for drawing highlight path.                                                                                                                 |
| `ranges` | [Int](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-int/index.html):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](https://developer.android.com/reference/kotlin/android/text/Highlights.Builder#) | this builder instance. |

### build

Added in[API level 34](https://developer.android.com/guide/topics/manifest/uses-sdk-element.html#ApiLevels)  

```
fun build(): Highlights
```

Build a new Highlights instance.

|                                                      Return                                                      ||
|--------------------------------------------------------------------------------------|----------------------------|
| [Highlights](https://developer.android.com/reference/kotlin/android/text/Highlights) | a new Highlights instance. |