Added in [API level 34](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels) Summary: [Ctors](https://developer.android.com/reference/android/text/Highlights.Builder#pubctors) \| [Methods](https://developer.android.com/reference/android/text/Highlights.Builder#pubmethods) \| [Inherited Methods](https://developer.android.com/reference/android/text/Highlights.Builder#inhmethods)

# Highlights.Builder

*** ** * ** ***


`
public
static
final

class
Highlights.Builder
`


`

extends https://developer.android.com/reference/java/lang/Object


`

`


`

|---|---|
| [java.lang.Object](https://developer.android.com/reference/java/lang/Object) ||
| ↳ | android.text.Highlights.Builder |

<br />

*** ** * ** ***

A builder for the Highlights.

## Summary

| ### Public constructors ||
|---|---|
| ` https://developer.android.com/reference/android/text/Highlights.Builder#Builder()() ` |

| ### Public methods ||
|---|---|
| ` https://developer.android.com/reference/android/text/Highlights.Builder` | ` https://developer.android.com/reference/android/text/Highlights.Builder#addRange(android.graphics.Paint,%20int,%20int)(https://developer.android.com/reference/android/graphics/Paint paint, int start, int end) ` Add single range highlight. |
| ` https://developer.android.com/reference/android/text/Highlights.Builder` | ` https://developer.android.com/reference/android/text/Highlights.Builder#addRanges(android.graphics.Paint,%20int[])(https://developer.android.com/reference/android/graphics/Paint paint, int... ranges) ` Add multiple ranges highlight. |
| ` https://developer.android.com/reference/android/text/Highlights` | ` https://developer.android.com/reference/android/text/Highlights.Builder#build()() ` Build a new Highlights instance. |

| ### Inherited methods |
|---|---|
| From class ` https://developer.android.com/reference/java/lang/Object ` |---|---| | ` https://developer.android.com/reference/java/lang/Object` | ` https://developer.android.com/reference/java/lang/Object#clone()() ` Creates and returns a copy of this object. | | ` boolean` | ` https://developer.android.com/reference/java/lang/Object#equals(java.lang.Object)(https://developer.android.com/reference/java/lang/Object obj) ` Indicates whether some other object is "equal to" this one. | | ` void` | ` https://developer.android.com/reference/java/lang/Object#finalize()() ` Called by the garbage collector on an object when garbage collection determines that there are no more references to the object. | | ` final https://developer.android.com/reference/java/lang/Class<?>` | ` https://developer.android.com/reference/java/lang/Object#getClass()() ` Returns the runtime class of this `Object`. | | ` int` | ` https://developer.android.com/reference/java/lang/Object#hashCode()() ` Returns a hash code value for the object. | | ` final void` | ` https://developer.android.com/reference/java/lang/Object#notify()() ` Wakes up a single thread that is waiting on this object's monitor. | | ` final void` | ` https://developer.android.com/reference/java/lang/Object#notifyAll()() ` Wakes up all threads that are waiting on this object's monitor. | | ` https://developer.android.com/reference/java/lang/String` | ` https://developer.android.com/reference/java/lang/Object#toString()() ` Returns a string representation of the object. | | ` final void` | ` https://developer.android.com/reference/java/lang/Object#wait(long,%20int)(long timeoutMillis, int nanos) ` Causes the current thread to wait until it is awakened, typically by being *notified* or *interrupted*, or until a certain amount of real time has elapsed. | | ` final void` | ` https://developer.android.com/reference/java/lang/Object#wait(long)(long timeoutMillis) ` Causes the current thread to wait until it is awakened, typically by being *notified* or *interrupted*, or until a certain amount of real time has elapsed. | | ` final void` | ` https://developer.android.com/reference/java/lang/Object#wait()() ` Causes the current thread to wait until it is awakened, typically by being *notified* or *interrupted*. | ||

## Public constructors

### Builder

```
public Builder ()
```

<br />

<br />

## Public methods

### addRange

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

```
public Highlights.Builder addRange (Paint paint, 
                int start, 
                int end)
```

Add single range highlight.

The `https://developer.android.com/reference/android/widget/TextView` and underlying `https://developer.android.com/reference/android/text/Layout` draws highlight in the
order of the `https://developer.android.com/reference/android/text/Highlights.Builder#addRange(android.graphics.Paint,%20int,%20int)` 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()
`

<br />

| Parameters ||
|---|---|
| `paint` | `Paint`: a paint object used for drawing highlight path. <br /> |
| `start` | `int`: an inclusive offset of the text. <br /> |
| `end` | `int`: an exclusive offset of the text. <br /> |

| Returns ||
|---|---|
| `https://developer.android.com/reference/android/text/Highlights.Builder` | this builder instance. <br /> |

### addRanges

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

```
public Highlights.Builder addRanges (Paint paint, 
                int... ranges)
```

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()
`

<br />

| Parameters ||
|---|---|
| `paint` | `Paint`: a paint object used for drawing highlight path. <br /> |
| `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. <br /> |

| Returns ||
|---|---|
| `https://developer.android.com/reference/android/text/Highlights.Builder` | this builder instance. <br /> |

### build

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

```
public Highlights build ()
```

Build a new Highlights instance.

<br />

| Returns ||
|---|---|
| `https://developer.android.com/reference/android/text/Highlights` | a new Highlights instance. <br /> |