DEV Community 👩‍💻👨‍💻

Hossain Khan
Hossain Khan

Posted on • Originally published at Medium on

Clickable link text for Android TextView — Kotlin Extension

Clickable link text for Android TextView — Kotlin Extension

Recently I have had to create UI that required user tappable/clickable text in the same text view. I know this is kind of unusual as the touch target for the view will likely be smaller compared to a button with no outline style. However, I wanted to share a quick Kotlin extension function that is dynamic and well tested.

Android TextView where “Register Now” is a tappable link with a callback.

Here is an example usage for generating clickable link within the same TextView

So, if your project requires something like this take a look at the following extension function for android.widget.TextView.

You should be able to easily convert this to Java if needed. Let me know if you find this useful. Cheers ✌️

Top comments (0)

👋 Hey, my name is Noah and I’m the one who set up this ad. My job is to get you to join DEV, so if you fancy doing me a favor, I’d love for you to create an account.

If you found DEV from searching around, here are a couple of our most popular articles on DEV: