Stay organized with collections
Save and categorize content based on your preferences.
Builder
class Builder
A builder for the Highlights.
Summary
Public constructors
Public methods
addRange
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. |
addRanges
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. |
build
fun build(): Highlights
Build a new Highlights instance.
Content and code samples on this page are subject to the licenses described in the Content License. Java and OpenJDK are trademarks or registered trademarks of Oracle and/or its affiliates.
Last updated 2025-02-10 UTC.
[[["Easy to understand","easyToUnderstand","thumb-up"],["Solved my problem","solvedMyProblem","thumb-up"],["Other","otherUp","thumb-up"]],[["Missing the information I need","missingTheInformationINeed","thumb-down"],["Too complicated / too many steps","tooComplicatedTooManySteps","thumb-down"],["Out of date","outOfDate","thumb-down"],["Samples / code issue","samplesCodeIssue","thumb-down"],["Other","otherDown","thumb-down"]],["Last updated 2025-02-10 UTC."],[],[],null,["# Highlights.Builder\n\nAdded in [API level 34](https://developer.android.com/guide/topics/manifest/uses-sdk-element.html#ApiLevels)\n\nBuilder\n=======\n\n*** ** * ** ***\n\nKotlin \\|[Java](/reference/android/text/Highlights.Builder \"View this page in Java\") \n\n```\nclass Builder\n```\n\n|---|--------------------------------------|\n| [kotlin.Any](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-any/index.html) ||\n| ↳ | [android.text.Highlights.Builder](#) |\n\nA builder for the Highlights.\n\nSummary\n-------\n\n| Public constructors ||\n|----------------------------------|---|\n| [Builder](#Builder())`()` \u003cbr /\u003e |\n\n| Public methods ||\n|---------------------------------------------------------|----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|\n| [Highlights.Builder](#) | [addRange](#addRange(android.graphics.Paint,%20kotlin.Int,%20kotlin.Int))`(`paint:` `[Paint](../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. |\n| [Highlights.Builder](#) | [addRanges](#addRanges(android.graphics.Paint,%20kotlin.Int))`(`paint:` `[Paint](../graphics/Paint.html#)`, `vararg` `ranges:` `[Int](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-int/index.html)`)` Add multiple ranges highlight. |\n| [Highlights](/reference/kotlin/android/text/Highlights) | [build](#build())`()` Build a new Highlights instance. |\n\nPublic constructors\n-------------------\n\n### Builder\n\n```\nBuilder()\n```\n\nPublic methods\n--------------\n\n### addRange\n\nAdded in [API level 34](https://developer.android.com/guide/topics/manifest/uses-sdk-element.html#ApiLevels) \n\n```\nfun addRange(\n paint: Paint, \n start: Int, \n end: Int\n): Highlights.Builder\n```\n\nAdd single range highlight. The [android.widget.TextView](../widget/TextView.html#) and underlying [Layout](/reference/kotlin/android/text/Layout) draws highlight in the order of the [addRange](#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() `\n\n| Parameters ||\n|---------|--------------------------------------------------------------------------------------------------------------|\n| `paint` | [Paint](../graphics/Paint.html#): a paint object used for drawing highlight path. |\n| `start` | [Int](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-int/index.html): an inclusive offset of the text. |\n| `end` | [Int](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-int/index.html): an exclusive offset of the text. |\n\n| Return ||\n|-------------------------|------------------------|\n| [Highlights.Builder](#) | this builder instance. |\n\n### addRanges\n\nAdded in [API level 34](https://developer.android.com/guide/topics/manifest/uses-sdk-element.html#ApiLevels) \n\n```\nfun addRanges(\n paint: Paint, \n vararg ranges: Int\n): Highlights.Builder\n```\n\nAdd 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() `\n\n| Parameters ||\n|----------|-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|\n| `paint` | [Paint](../graphics/Paint.html#): a paint object used for drawing highlight path. |\n| `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. |\n\n| Return ||\n|-------------------------|------------------------|\n| [Highlights.Builder](#) | this builder instance. |\n\n### build\n\nAdded in [API level 34](https://developer.android.com/guide/topics/manifest/uses-sdk-element.html#ApiLevels) \n\n```\nfun build(): Highlights\n```\n\nBuild a new Highlights instance.\n\n| Return ||\n|---------------------------------------------------------|----------------------------|\n| [Highlights](/reference/kotlin/android/text/Highlights) | a new Highlights instance. |"]]