Create Clickable Link on TextView

Arief Bayu Purwanto
Bits and pieces of my mind
2 min readJun 12, 2020
Photo by chuttersnap on Unsplash

Note: This has been posted on my old blog 9 years ago. I decided to rewrite it here again as a way to preserve and refreshed using Kotlin

Technique explained in this post usually used in the login/register screen. Sometime as a way to guide users to “Terms and Conditions” of your app or to go to login or register screen. But it can be applied to a whole lot of different scenarios.

An example of “Sign up” link within another text view
Image by Nani Hedge.

Fill The TextView

We will fill our TextView with string generated using HTML syntax.

Set the TextView to be clickable and assign LinkMovementMethod as the MovementMethod value. These two line will allow us to click the link.

Under The Hood Explanation

As you can see, out register link above is set to launch.ltactivity://OpenPage?page=register. This method uses android internal intent communication’s mechanism. By having launch.ltactivity://, we tell android to call whatever activity that listen to it. Since we want our app to do it, we’ll have to catch using intent filter that specified inside manifest.xml:

After this, we just need to read the data sent to LTActivity. For example, for the above URL, when clicked, will go to LTActivity and using the following syntax:

will produce:

Btw, you should read this documentation from Mozilla about “What is a URL?” for more information.

--

--

Arief Bayu Purwanto
Bits and pieces of my mind

Project Leader at AkuPeduli.org | Mozilla Representative | @bloggerngalam | @ariefbayu | blogging at https://ariefbayu.dev