Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Hyperlink in Android

I have a question: How can I place a hyperlink WITHIN a text-block of normal text? I have some text and in the text I mention a URL and I want this URL to be in a different color, underlined and click-able.

I know hyperlinks in android can be placed with "Linkify".. and i have referred android docs page

Consider the same above paragraph with "android docs" i want to display in android.....

like image 571
Paresh Mayani Avatar asked Jul 08 '10 13:07

Paresh Mayani


People also ask

How do you make text clickable on Android?

In Android, the most common way to show a text is by TextView element. The whole text in the TextView is easy to make clickable implementing the onClick attribute or by setting an onClickListener to the TextView.


2 Answers

@Fedor.... i have found to give links from API Demos .

this approach is finally be used for giving link in between text of paragraph.

     SpannableString ss = new SpannableString("text4: Click here 
                                                  to dial the phone.");

    ss.setSpan(new StyleSpan(Typeface.ITALIC), 0, 6,
           Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);

    ss.setSpan(new URLSpan("tel:4155551212"), 13, 17,
           Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);

    TextView t4 = (TextView) findViewById(R.id.TextView01);
    t4.setText(ss);
    t4.setMovementMethod(LinkMovementMethod.getInstance());
like image 159
Paresh Mayani Avatar answered Oct 11 '22 00:10

Paresh Mayani


Take a look at that TextView underline phone number and hyperlink

But I can see Linkify doesn't provide you the functionality you need. Not a problem, you can implement it manually. Just add ClickableSpans and handlre click. Code sample here http://www.orangeapple.org/?p=354.

like image 36
Fedor Avatar answered Oct 11 '22 00:10

Fedor