Logo Icon Logo
A Crowd-sourced Cookbook on Writing Great Android® Apps
GitHub logo Twitter logo OReilly Book Cover Art

Converting Text into Hyperlinks

In Chapter: Networked Applications
Author: Rachee Singh ('racheesingh')
Published? true
FormatLanguage: WikiFormat


You need to make webpage URLs into hyper-links in a TextView of your Android app


Use the autolink property for a TextView


You are setting the URL: 'www.google.com' as part of the text in a TextView but you want this text to be a hyper-link so that the user can open the web page in a browser by clicking on it. To achieve this, add a property to the TextView:

android:autoLink = "all" 

Now, in the Activity's code you can set any text to the TextView and all the URLs will be converted to hyper-links!

linkText = (TextView)findViewById(R.id.link);
linkText.setText("The link is: www.google.com");