Skip to content
Related Articles

Related Articles

Create Clickable Hyperlinks in TextView in Android with Kotlin

View Discussion
Improve Article
Save Article
Like Article
  • Last Updated : 30 Jan, 2022

TextView is used to display text in Android. text can be characters, numbers, strings, and paragraphs. We can also display web URLs in the TextView. However, these links are non-clickable and cannot be used for website navigation. Moreover, we cannot create hyperlinks directly into the TextView.

Clickable Hyperlinks in TextView in Android with Kotlin

So in this article, we will show you a correct way of creating hyperlinks in TextView that are clickable and navigable in Android. Follow the below steps once the IDE is ready.

Step by Step Implementation

Step 1: Create a New Project in Android Studio

To create a new project in Android Studio please refer to How to Create/Start a New Project in Android Studio. We demonstrated the application in Kotlin, so make sure you select Kotlin as the primary language while creating a New Project.

Step 2: Create a hyperlink in the strings.xml file

Go to res > values > strings.xml and add the following code.


    <string name="app_name">GFG | TextViewHyperlinks</string>
      <!--Add the below string-->
    <string name="hyperlink">Open <a href="">GeeksforGeeks portal</a></string>

Step 3: 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. Add a TextView to display the Hyperlink.


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

Step 4: Working with the MainActivity.kt file

Go to the MainActivity.kt file and refer to the following code. Below is the code for the MainActivity.kt file. Comments are added inside the code to understand the code in more detail.


package org.geeksforgeeks.textviewhyperlinks
import android.os.Bundle
import android.text.method.LinkMovementMethod
import android.widget.TextView
class MainActivity : AppCompatActivity() {
    override fun onCreate(savedInstanceState: Bundle?) {
        // Declaring and Initializing 
        // the TextView from the layout file
        val mTextView = findViewById<TextView>(
        // Finding and displaying the content
        // that consists a URL as a hyperlink
        mTextView.movementMethod = LinkMovementMethod.getInstance()


You can see that the string is underlined and on click opens the web page. (Keep the device connected to the internet)

My Personal Notes arrow_drop_up
Recommended Articles
Page :

Start Your Coding Journey Now!