Android TextView में Linkify से क्लिकेबल लिंक्स बनाएं
Linkify TextView में URLs, ईमेल, फोन नंबर्स को ऑटोमेटिकली क्लिकेबल लिंक्स में बदल देता है - HTML हाइपरलिंक की तरह।
चरण 1: प्रोजेक्ट सेटअप
Android Studio: File → New Project।
चरण 2: लेआउट (activity_main.xml)
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout
xmlns:android="https://schemas.android.com/apk/res/android"
xmlns:app="https://schemas.android.com/apk/res-auto"
xmlns:tools="https://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity">
<TextView
android:id="@+id/result"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="परिणाम डेटा"
android:textSize="20sp"
android:padding="10dp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toTopOf="parent" />
</androidx.constraintlayout.widget.ConstraintLayout>
चरण 3: MainActivity.java - Linkify लागू करें
package com.example.andy.myapplication;
import android.os.Bundle;
import androidx.appcompat.app.AppCompatActivity;
import android.text.util.Linkify;
import android.widget.TextView;
public class MainActivity extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
TextView textView = findViewById(R.id.result);
// टेक्स्ट जिसमें URL, ईमेल, फोन नंबर हैं
String content = "TutorialsPoint.com से सीखें। " +
"संपर्क: info@tutorialspoint.com या कॉल करें: +91-9876543210";
textView.setText(content);
// Linkify लागू करें - सभी प्रकार के लिंक्स डिटेक्ट करें
Linkify.addLinks(textView, Linkify.ALL);
}
}
Linkify मास्क प्रकार:
| कॉन्स्टेंट | डिटेक्ट करता है | एक्शन |
|---|---|---|
Linkify.WEB_URLS | https://, https://, www. | ब्राउज़र में खोलता है |
Linkify.EMAIL_ADDRESSES | user@domain.com | ईमेल ऐप खोलता है |
Linkify.PHONE_NUMBERS | फोन नंबर पैटर्न्स | डायलर खोलता है |
Linkify.ALL | उपरोक्त सभी | सभी के लिए उपयुक्त ऐप |
Linkify.MAP_ADDRESSES | पते | मैप्स ऐप खोलता है |
मैनिफेस्ट में इंटरनेट परमिशन (वेब URL के लिए)
<uses-permission android:name="android.permission.INTERNET" />
कस्टम लिंक पैटर्न (एडवांस्ड):
Pattern pattern = Pattern.compile("\\b(MyApp://\\S+)\\b");
String scheme = "MyApp://";
Linkify.addLinks(textView, pattern, scheme);
आउटपुट



नतीजा: TextView में URLs, ईमेल, फोन नंबर्स ऑटोमेटिकली हाइलाइट होते हैं और क्लिक करने पर संबंधित ऐप खुलता है।