Skip to content
Related Articles

Related Articles

Improve Article
Save Article
Like Article

How to Detect Text Type Automatically in Android?

  • Last Updated : 26 Apr, 2021

In this article, we are going to implement a feature related to TextView which is very important in every perspective. While using any social Media App or Notes app you may have seen that when we type something, it automatically detect the text type like email, phone, or a URL. Here we are going to implement that feature. A sample video 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.  

Step by Step Implementation

Step 1: Create a New Project

Attention reader! Don’t stop learning now. Get hold of all the important Java Foundation and Collections concepts with the Fundamentals of Java and Java Collections Course at a student-friendly price and become industry ready. To complete your preparation from learning a language to DS Algo and many more,  please refer Complete Interview Preparation Course.

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: Working with the activity_main.xml file

Navigate to the app > res > layout > activity_main.xml and add the below code to that file. Below is the code for the activity_main.xml file. 


<?xml version="1.0" encoding="utf-8"?>
        android:textSize="32sp" />
        android:textSize="32sp" />
        android:textSize="32sp" />

Step 3: Working with the file

Go to the file and refer to the following code. This is how we are implementing auto-detect text type of our text

Linkify.addLinks(email, Linkify.ALL);

Below is the code for the file. Comments are added inside the code to understand the code in more detail.


import android.os.Bundle;
import android.text.util.Linkify;
import android.widget.TextView;
public class MainActivity extends AppCompatActivity {
    protected void onCreate(Bundle savedInstanceState) {
        //initialising the layout
        TextView mobile = (TextView) findViewById(;
        TextView google = (TextView) findViewById(;
        TextView email = (TextView) findViewById(;
        // setting the email
        // setting the mobile number
        // setting the web url to visit
        // linking all type of text
        Linkify.addLinks(email, Linkify.ALL);
        Linkify.addLinks(mobile, Linkify.ALL);
        Linkify.addLinks(google, Linkify.ALL);


My Personal Notes arrow_drop_up
Recommended Articles
Page :

Start Your Coding Journey Now!