2

I want to display a clickable URL in the message of android so i need your suggestion how to do that? I used Linkify but it is used for only text view but i want it in the StringBuilder.

StringBuilder shareMsgBuilder = new StringBuilder("google.com");

Sunil Pal
  • 91
  • 1
  • 6
  • 1
    use `SpannableString[Builder]` and call `setSpan()` with `URLSpan` object, alsp you can use `Linkify.addLinks(Spannable text, ...)` – pskink Oct 06 '14 at 06:50
  • Look at this http://android2011dev.blogspot.jp/2013/10/open-url-linkify-text-and-spannable.html – NTK88 Oct 06 '14 at 06:53
  • Refer this link :http://stackoverflow.com/questions/4303160/how-can-i-make-links-in-fromhtml-clickable-android – bala Jun 02 '16 at 06:55

1 Answers1

1

Define a TextView containing text google.com inside Layout file, and write an attribute autoLink and set its value web which will let you open the URL in browser.

 <TextView
      android:text="http://www.google.com"
      android:autoLink="web"/>

Other autoLink attributes are email, phone, map, you can also use multiple attributes in same TextView by separating them using | like web|email|phone.

Apurva
  • 7,871
  • 7
  • 40
  • 59