Android: Make your TextView look like a hyperlink

There's no shortage of posts regarding Linkify and automatically making part of the TextView clickable. Just search for "android textview hyperlink" and you'll get a fair idea.

TextView tvMessage = (TextView) findViewById(;

And the result would be something like...


But when you don't want the text to include http:// is when you'll have to look elsewhere.


To get this, it's really simple. You can even make a quick TextView subclass out of it.

* Sets a hyperlink style to the textview.
public static void makeTextViewHyperlink(TextView tv) {
SpannableStringBuilder ssb = new SpannableStringBuilder();
ssb.setSpan(new URLSpan("#"), 0, ssb.length(), Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
tv.setText(ssb, TextView.BufferType.SPANNABLE);

And to set up the click handler, just use an ordinary OnClickListener so you can handle the click any way you want.

TextView tv = (TextView) findViewById(;
tv.setOnClickListener(new OnClickListener() {
public void onClick(View v) {
Intent intent = new Intent(getApplicationContext(), RecipeActivity.class);

Done, like a BOSS!

While you're at it, check out my Diablo II Runewords app!


Copyright © Twig's Tech Tips
Theme by BloggerThemes & TopWPThemes Sponsored by iBlogtoBlog