How to Highlight Text in Android TextView?

Written by Biajid

Hi there, I'm Biajid, a devoted tech lover who specializes in tackling technical difficulties relate...

https://www.androidsparks.com

   Review by Android Sparks

Hi there, I'm androidsparks, a devoted tech lover who specializes in tackling technical difficulties...

https://www.androidsparks.com

How
Why

Last Updated: May 20, 2023


Sometimes we need to indicate focus on a particular line or words of a document while reading text on Android. The text highlighter is one of the most used features on different Android Apps. You may find this popular function in different educational note-taking pdf reader applications on Android.

The main use of text highlighter is to indicate a word or sentence and is also used for keyword research on Android. This article will discuss how to highlight text in Android textview and how we can implement this feature in Android Applications. So, stick to the article and read through it carefully.

How to highlight text on Android?

You can easily highlight texts on your Android by following some simple steps. Follow the instructions below if you want to highlight texts on your Android–

  • Open an app or a document on your device that contains the text. (i.e. Gmail)
How to Highlight Text in Android TextView
  • Long tap on the text that you want to highlight. Two tear-drop sliders will appear.
How to Highlight Text in Android TextView
  • Touch the right slider and drag it over the text you want to highlight. Release the slider if completed highlighting.
How to Highlight Text in Android TextView
  • Then, there you may find three options, respectively “Select All,” “Copy,” and “Share.”
How to Highlight Text in Android TextView
  • Now, take any option you want.

How to implement the Text highlight feature on Android?

This part of the article will provide you with a step-by-step guide to implementing the text highlight feature on your Android. Follow the instructions below to implement the text highlight feature on your Android–

Prerequisites

Step-by-step guide

Step 1: Create a “New Project”  and choose “JAVA” as the programming language on the Android Studio.

Step 2: Add dependency of Text Highlighter in the “build.gradle” file.

Step3: Go to gradle scripts> build.gradle (Module).

Step 4: Add “ implementation ‘com.xeoh.android:text-highlighter:1.0.3” in the build.gradle file in the dependencies tab.

Step 5: Now, tap on the “Sync now” button to sync your file to build.gradle().

Step6: Open the activity_main.xml file and create a Text Highlighter in it. Add the following lines below to the XML file.

<?xml version="1.0" encoding="utf-8"?>

<RelativeLayout 

    xmlns:android="http://schemas.android.com/apk/res/android"

    xmlns:tools="http://schemas.android.com/tools"

    android:layout_width="match_parent"

    android:layout_height="match_parent"

    tools:context=".MainActivity">

    <!--Scroll view for scrolling-->

    <ScrollView

        android:layout_width="match_parent"

        android:layout_height="300dp"

        android:layout_alignParentBottom="true"

        android:layout_centerHorizontal="true">

        <!--Linear layout to arrange elements one below another-->

        <LinearLayout

            android:layout_width="match_parent"

            android:layout_height="wrap_content"

            android:padding="30dp">

            <!--TextView to display text-->

            <TextView

                android:id="@+id/textView"

                android:layout_width="wrap_content"

                android:layout_height="wrap_content"

                android:layout_alignParentBottom="true"

                android:layout_centerHorizontal="true"

                android:text="Android is a mobile operating system based on a modified version of the Linux kernel and other open source software, designed primarily for touchscreen mobile devices such as smartphones and tablets. Android is developed by a consortium of developers known as the Open Handset Alliance and commercially sponsored by Google. It was unveiled in November 2007, with the first commercial Android device launched in September 2008.

 It is free and open source software; its source code is known as Android Open Source Project (AOSP), which is primarily licensed under the Apache License. However most Android devices ship with additional proprietary software pre-installed,[10] most notably Google Mobile Services (GMS)[11] which includes core apps such as Google Chrome, the digital distribution platform Google Play and associated Google Play Services development platform. About 70 percent of Android smartphones run Google's ecosystem;[12] competing Android ecosystems and forks include Fire OS (developed by Amazon) or LineageOS. However the 'Android' name and logo are trademarks of Google which impose standards to restrict 'uncertified' devices outside their ecosystem to use Android branding.[13][14]

The source code has been used to develop variants of Android on a range of other electronics, such as game consoles, digital cameras, portable media players, PCs and others, each with a specialized user interface. Some well known derivatives include Android TV for televisions and Wear OS for wearables, both developed by Google. Software packages on Android, which use the APK format, are generally distributed through proprietary application stores like Google Play Store, Samsung Galaxy Store, and Huawei AppGallery, or open source platforms like Aptoide or F-Droid.

Android has been the best-selling OS worldwide on smartphones since 2011 and on tablets since 2013. As of May 2017, it has over two billion monthly active users, the largest installed base of any operating system, and as of August 2020, the Google Play Store features over 3 million apps.[15] The current stable version is Android 11, released on September 8, 2020. " />

        </LinearLayout>

    </ScrollView>

    <!--Button to search text-->

    <Button

        android:id="@+id/button"

        android:layout_width="match_parent"

        android:layout_height="wrap_content"

        android:layout_below="@+id/search"

        android:layout_centerInParent="true"

        android:layout_margin="20dp"

        android:padding="10dp"

        android:text="Search" />

    <!--EditText to give text input-->

    <EditText

        android:id="@+id/search"

        android:layout_width="match_parent"

        android:layout_height="wrap_content"

        android:layout_alignParentTop="true"

        android:layout_centerHorizontal="true"

        android:layout_margin="10dp"

        android:ems="10"

        android:hint="Search"

        android:inputType="text"

        android:text="" />

</RelativeLayout>

Step 7: Now, open the MainActivity.java file and write the following code inside the MainActivity.java file.

import android.graphics.Color;

import android.os.Bundle;

import android.view.View;

import android.widget.Button;

import android.widget.EditText;

import android.widget.TextView;

import androidx.appcompat.app.AppCompatActivity;

import com.xeoh.android.texthighlighter.TextHighlighter;

public class MainActivity extends AppCompatActivity {

    // Variable for button,

    // edit text and text view given

    Button button;

    EditText editText;

    TextView textView;

    @Override

    protected void onCreate(Bundle savedInstanceState) {

        super.onCreate(savedInstanceState);

        setContentView(R.layout.activity_main);

        // Accepted through Id's

        button = (Button) findViewById(R.id.button);

        editText = (EditText) findViewById(R.id.search);

        textView = (TextView) findViewById(R.id.textView);

        button.setOnClickListener(new View.OnClickListener() {

            @Override

            public void onClick(View view) {

                new TextHighlighter()

                        .setBackgroundColor(Color.parseColor("#FFFF00"))

                        .setForegroundColor(Color.GREEN)

                        .addTarget(textView)

                        .highlight(editText.getText().toString(), TextHighlighter.BASE_MATCHER);

            }

        });

    }

}

Step 8: Now, open the AndroidManifest.xml file and add the following line to it:

android:windowSoftInputMode=”adjustNothing|stateHidden”>

Step 9: Write the code below into the AndroidManifest.xml –

<?xml version="1.0" encoding="utf-8"?>

<manifest xmlns:android="http://schemas.android.com/apk/res/android"

    package="com.example.emoji_slider">

    <application

        android:allowBackup="true"

        android:icon="@mipmap/ic_launcher"

        android:label="@string/app_name"

        android:roundIcon="@mipmap/ic_launcher_round"

        android:supportsRtl="true"

        android:theme="@style/Theme.Emoji_slider">

        <activity android:name=".MainActivity"

            android:windowSoftInputMode="adjustNothing|stateHidden">

            <intent-filter>

                <action android:name="android.intent.action.MAIN" />

                <category android:name="android.intent.category.LAUNCHER" />

            </intent-filter>

        </activity>

    </application>

</manifest>

Step 10: Done. You have successfully implemented the text highlight feature on your Android app.

FAQs

How can I highlight something on my Android?

You can highlight something on your Android device by just using your fingers. To highlight any text on your Android device, tap on the text and drag over the line or words from the text you need to highlight.

Which app can I install to highlight text on Android?

There are many different applications for Android that support text highlighting. The best choice is to use the in-built text viewer or pdf reader app on your Android. Besides, you can search for Android text highlighter on the Google play store and install the app that fills your requirements.

Why should I highlight text on Android?

Text highlighting is a popular feature on Android that users can use to seek attention to the critical and sensitive information in a document and text. Highlighting is effective because it allows the readers to find out the main points and asks them to take out the important parts only.

How do I highlight text on my Samsung phone?

There are several ways to highlight text on Samsung phones. To highlight any text on your Android device, tap on the text and drag over the line or words from the text you need to highlight.

Final Words

So, that was all about highlighting text in the Android text view. Hopefully, this article on how to highlight text in Android textview has helped you highlight texts on your Android device. If you face any issues while executing the, let us know in the comment section.

Biajid

Hi there, I'm Biajid, a devoted tech lover who specializes in tackling technical difficulties related to Android phones and operating systems. Over the years, I've gained extensive experience in resolving complex issues and have become a seasoned expert in the field. I'm delighted to have you on my website, and I'm confident that the resources and solutions provided here will prove to be valuable to you

UnhelpfulMostly unhelpfulPossibly helpfulMostly helpfulVery helpful (No Ratings Yet)
Loading...

Last Updated: May 20, 2023

Post View : 120

Recent Posts