TextHighlighter

Additional

Language
Java
Version
N/A
Created
Aug 14, 2017
Updated
Aug 15, 2017
Owner
Lee Jeo (xeoh)
Contributor
Lee Jeo (xeoh)
1
Activity
Badge
Generate
Download
Source code
APK file

Announcement

Android TextHighlighter

Introduction

highlights every View which inherits TextView(i.e. TextView, Button, EditText). Set targets and Colors. Then highlight any word.

Requirements

Android API ≥ 2.3 (API Level 9)

Gradle

You can import TextHighlighter from jcenter.

repositories {
    jcenter()
}

dependencies {
    compile 'com.xeoh.android:text-highlighter:1.0.1'
}

Usage

private TextHighlighter textHighlighter = new TextHighlighter()
      .setBackgroundColor(Color.parse("#FFFF00"))
      .setForegroundColor(Color.RED)
      .addTarget(findViewById(R.id.anyTextView))
      .highlight("word", TextHighlighter.BASE_MATCHER);

// invalidate after add more targets
textHighlighter.addTarget(findViewById(R.id.anyButton))
      .invalidate(TextHighlighter.BASE_MATCHER);

// invalidate after color changes
textHighlighter.setForegroundColor(Color.GREEN)
      .invalidate(TextHighlighter.BASE_MATCHER);

// change matcher to case insensitive
textHighlighter.invalidate(TextHighlighter.CASE_INSENSITIVE_MATCHER);

/*
You can use multiple TextHighlighter for multiple keyword or multiple
styles. However, if two highlighter highlights same word, priority depends
on order of highlight(...) function call
*/

See sample application

License

TextHighlighter is available under the MIT license. See the LICENSE file for more info.