Android: textview hyperlink

android textview underline
android textview link to another activity
how to set url in textview android
android multiple links in textview
open link on textview click
change link color in textview android

I know that if you put a link in a textview it will work but if I want to display for example:

google stackoverflow

and not the whole link(just the tag) How do i make those links clickable?

You could have two separate TextViews and you could align them accordingly in your layout if needed:

            "<a href=\"\">google</a> "));

                "<a href=\"\">stackoverflow</a> "));

Then if you want to strip the "link underline". Create a class:

public class URLSpanNoUnderline extends URLSpan {
    public URLSpanNoUnderline(String url) {
    @Override public void updateDrawState(TextPaint ds) {

Then add this method in your main Activity class where you have the TextViews

private void stripUnderlines(TextView textView) {
    Spannable s = new SpannableString(textView.getText());
    URLSpan[] spans = s.getSpans(0, s.length(), URLSpan.class);
    for (URLSpan span: spans) {
        int start = s.getSpanStart(span);
        int end = s.getSpanEnd(span);
        span = new URLSpanNoUnderline(span.getURL());
        s.setSpan(span, start, end, 0);

And then just call this after you initialised the TextViews (in your onCreate):


Android TextView Hyperlink, Here is the solution that worked for me, after looking through multiple Stack Overflow posts. I've tailored it to your implementation: 1. Remove  The TextView is a widget in Android that allows you to display text to the user. It is also possible to use the Android TextView widget to create a hyperlink which can load a web page in a mobile web browser when clicked. To create a clickable hyperlink in your Android app using the TextView widget follow the steps below.

TextView t2 = (TextView) findViewById(;


<string name="google_stackoverflow"><a href="" rel="nofollow" target="blank">google stack overflow</a></string>

The link is, "Android: textview hyperlink"

and the tag is, "google stack overflow"

Define the first code block in your java and the second code block in your strings.xml file. Also, be sure to reference the id of the textView from your page layout in your java.

How to Create a Hyperlink Using Android TextView – Learn to Droid, To create a clickable hyperlink in your Android app using the TextView widget follow the steps below. Create a new String resource in the strings.xml resource file representing the text to be placed inside the TextView. In your String resource use HTML markup to insert the hyperlink using an anchor tag. Create HyperLink text in android apps <a href=””> to open given clickable link in mobile Web Browser. Hyper Linking is the most usable method for all website because with the use of hyperlink website developer can insert links on their web pages and on each & every link holds a unique web address. Now with the use of spanned variable android developers can also insert hyperlinks in android apps using textview tag.

android:autoLink="web" simply works if you have full links in your HTML. The following will be highlighted in blue and clickable:

How to use TextView onClick event in android, Step 1 − Create a new project in Android Studio, go to File ⇒ New href="https://​">Tap here to open Link</a></string>  Create an android project in the android studio (Follow this tutorial: Android First Program in Android Studio ). Step 2. Open the strings.xml file. Step 3. Add this text in the strings.xml file. <resources> <string name="app_name">Android TextView Clickable</string> <string name="text_link_ehs"> <a href=""></a></string> <string name="text_go_to"><a href="">Go to EyeHunts</a></string> </resources>.

Very simple way to do this---

In your Activity--

 TextView tv = (TextView) findViewById(;
 tv.setText(Html.fromHtml("<a href=> STACK OVERFLOW "));

Then you will get just the Tag, not the whole link..

Hope it will help you...

How to create clickable links in a textView on Android?, You probably used apps which have a TextView with a link to a Terms of Service page, or Privacy Notes, or Help Center, or anything else that is  If you use the android:autoLink="web" property then you'll have to override it with textView.setAutoLinkMask(0); before calling setText() on your TextView. You can also set the link to be clickable in your activity instead like in Harshal's answer if you prefer, but I left it since you already had it in the layout.

this should work.

TextView t2 = (TextView) findViewById(;


<TextView android:layout_width="wrap_content"
android:layout_height="wrap_content" android:text="@string/txtCredits"

How to add link inside text in Android - Kirill Suslov, Add Hyperlink in android application through textview.Create insert HyperLink text in android apps to open given clickable link in Web Browser. Android TextView Hyperlink . Posted by: admin May 10, 2020 Leave a comment. Questions: I’m implementing a TextView with a string containing two hyperlinks as below

Add Hyperlink in android application through textview, How to add a hyperlink programmatically in a TextView in Android. activity_main.​xml. <RelativeLayout xmlns:android="http://  This example demonstrates how do I create clickable links in a textView on android. Step 1 − Create a new project in Android Studio, go to File ⇒ New Project and fill all required details to create a new project.

How to add a hyperlink programmatically in a TextView in Android, hyperlink textview android, how to put clickable links on youtube video android studio, how to Duration: 3:13 Posted: Aug 21, 2017 You should get a TextView like the one in the following screenshot and when you tap on the hyperlink the ClickableSpan->onClick () method should be called, so you can do your operations and let the browser open the link!

How to create the links in textview clickable, Android: textview hyperlink. I know that if you put a link in a textview it will work but if I want to display for example: google stackoverflow. and not the whole  In xml file of TextView tag : android:autoLink="web" //link the content of web android:textColorLink="#FFFFFF" //change the color of the link

  • Check out this:
  • possible duplicate of How do I make links in a TextView clickable?
  • Several of the answers here call Html.fromHtml, and either don't use strings.xml for the hypertext or obfuscate the hypertext in the XML (e.g., "&lt;" replacing "<" in the XML file). This unnecessarily complicates matters. AFAICT, the most correct answer would be to type the HTML anchor tag directly in strings.xml, make sure the autolink property for the TextView is not set, then use setMovementMethod to set the LinkMovementMethod. There are a couple of answers that already show how to do this.
  • Possible duplicate of Make a hyperlink textview in android
  • Note: this will not work if you've set in your TextView's properties to autoLink some properties! If you have, you must call textView.setAutoLinkMask(0); before you call setText()
  • I like your way best. IMHO it is the cleanest.
  • This works with multiple links. e.g <string name="name">Examples: <a href="">Link 1</a> and <a href="">Link 2</a></string>
  • Works great with databinding as well: just define a BindingAdapter for an attribute like "containsLinks" and then set the movement method in the adapter.
  • yes and for that you can include this in your string resource <string name="txtCredits"><a href="">Google</a></string>.
  • Ill try that! Thank you!
  • Make sure that you do not have anything selected in autolink property. If there is anything selected in autolink property LinkMovementMethod.getInstance() does not work for that textview