Text Highlighter in Android
Text Highlighter is one of the popular functions in most apps. You can get to see this function in Notes keeping application or in any educational application. The main function of this feature is that it highlights the searched word in any document. In this article, we are going to see how to implement Text Highlighter in our Android App. A sample GIF is given below to get an idea about what we are going to do in this article. Note that we are going to implement this project using the Java language.
Application of Text Highlighter
- The main feature of using this Text Highlighter is that it highlights the searched word in your app.
- It tells you how much time the searched word is repeated and it gets highlighted.
- It is used for keyword research in an application.
|.setBackgroundColor()||Use to set Background Color.|
|.setForegroundColor()||Use to set Text Color.|
|.addTarget()||Use to search a word from certain document.|
|.highlight()||Use to highlight the searched text.|
Step by Step Implementation
Step 1: Create a New Project
To create a new project in Android Studio please refer to How to Create/Start a New Project in Android Studio. Note that select Java as the programming language.
Step 2: Add dependency of Text Highlighter library in build.gradle file
Then Navigate to gradle scripts and then to build.gradle(Module) level. Add below line in build.gradle file in the dependencies section.
Now click on Sync now it will sync your all files in build.gradle().
Step 3: Create a new Text Highlighter in your activity_main.xml file
Go to the activity_main.xml file and refer to the following code. Below is the code for the activity_main.xml file.
Step 4: Working with the MainActivity.java file
Go to the MainActivity.java file and refer to the following code. Below is the code for the MainActivity.java file. Comments are added inside the code to understand the code in more detail.
Step 5: Working with the AndroidManifest.xml file
Add the following line to the AndroidManifest.xml file inside the <activity> tag.
Below is the complete code for the AndroidManifest.xml file.