Reputation: 45
how can we show some additional information about a link in android i have seen examples that open links in the browser but that is not the case what i want
TextView tv = (TextView) findViewById(R.id.textView1);
String text = "This is just a test. Click this link here <a href=\"http://www.google.com\">Google</a> to visit google.";
tv.setMovementMethod(LinkMovementMethod.getInstance());
tv.setText(Html.fromHtml(text));
I have tried some code like above but it is for opening in a browser where else i want something like the below image
Upvotes: 2
Views: 257
Reputation: 180
What you are looking for is the OG tags from the link
This can be done by using JSoup and getting the information about the link and then extracting the OG tags from that.
You can checkout a simple library I made for the same task.
https://github.com/Priyansh-Kedia/OpenGraphParser
Upvotes: 0
Reputation: 25361
You can use basic HTML to format your text in TextView
. You can do something like bold, italic, link, etc. Here is a sample:
String code = "<p><b>First, </b><br/>" +
"Please press the link below.</p>" +
"<p><b>Second,</b><br/>" +
"Please insert the details of the event."
"<a href='http://www.google.com'>click here</a></p>";
TextView tv = (TextView) findViewById(R.id.textView1);
tv.setMovementMethod(LinkMovementMethod.getInstance());
tv.setText(Html.fromHtml(code, this, null));
tv.setTextSize(16);
Upvotes: 0
Reputation: 73494
That can be done using a URLSpan.
TextView tv = (TextView) findViewById(R.id.textView1);
SpannableString text = new SpannableString("This is just a test. Click this link here to visit google.");
text.setSpan(new URLSpan("http://www.google.com", 37, 41, 0));
tv.setText(text);
There are also several types of other Spans that can be really useful to style text. The 37 and 41 are the start and end indexes of the text to style.
Also here is an excellent blog post by Flavien Laurent on the many uses of Spans.
Upvotes: 1
Reputation: 161
I think splitting it into 2 text views is the best option. Here is a similar thread:
android: html in textview with link clickable
Hope this helps.
Upvotes: 0