I have a textview whose text is some html including hyperlinks. I have set the textview property android:autoLink="web" so that when user clicks the link, the link open in a browser. Now I want to get url when clicked because URLs I am getting from server, have absolute and relative addresses as well. I want to make it absolute in case url is relative. Any idea?
write an if statement on TextView click function to manipulate relative urls to absolute.
Related
So i have a html string which contains a
So after i set this in a text view in android
i need only the tag with the href tag inside of it to be clickable and then redirect it to the corresponding link . How can i do that.
"<body style='background-color:lightgreen;'><b style='color:red;'>App</b><br/>ABC <a href='redirect'>XYZ</a> App. Lorum Ipsum.</body>"
I want the XYZ link above to be set in a text view for which i am Using
Html.fromHtml()
after this the text is set . I want the "XYZ" text to be clickable and redirect me to the corresponding link. How can that be done?
Assuming you're using Java and not Kotlin, as you didn't point that out in your question, but this is the same idea.
If you want the textview to be clickable and have it work like a link
Use something like Pattern or Substring to manually parse the string to get the URL. (Bad idea)
Then set an setOnClickListener for the textView you want to redirect the user to. This should have an Intent and all that jazz in it.
I have a webView that loads a page. How do I copy all visible text on the webView? I don't want the innerHTML. I want the visible text. In other words, I want the same text that can be achieved by "selecting all" and copying.
Use a HTML parser which can give you nodes under your body element and keep aggregating text present inside each node. You could use this https://jsoup.org/
as a parser, it is quite established.
In my application (target 4.0), I have a chunk of HTML (which was pulled and parsed from a webpage) that I am displaying in a TextView. This HTML contains a large number of links (up to 100), most of which are relative, but some are absolute. I want the user to be able to click these relative urls URLs to launch a web browser.
How can I do this without going through the HTML and changing the URLs? Can I tap into a link click event?
You have to set a WebViewClient to your WebView and override shouldOverrideUrlLoading (and perhaps onLoadResource too).
You can match URL (and other patterns) using Linkifyand you can parse your content to use <a> tags like this:
Android Make hyperlinks in textview clickable
In other words, you need the href to contain a fully qualified URL, but you can still display the relative URL to the user.
No client URL works without full qualification, so you need to give the client a context. But this allows you to display relative URL's to the user.
I have a ListView with tweets that have urls in them. I want the user to stay in my app when they click on the links. Direct them to a webview to display the url when they click on the url. Can Linkify be used to redirect not the url, but the processing of the url to a Webview?
You can do 2 things. One is to modify Linkify to support launching your own Activity. Or you could write your own regex to match those links and create clickable spans in your text to achieve it.
The second approach is presented here: Android: Launch activity from clickable text
I have textview in my app. I have a string which I set in the textview.
The string is HTML string which has lots of html like images, bold and italics.
I used code as follows:
content.setText(Html.fromHtml(articledet.toString(), imgGetter, null));
I just want the links should be click-able. I achieved that easily. What I want when user clicks on the link, link should be opened in browser but I also want to track what external links where clicked.
i.e. On click of link, I should be able to write URL in a file.
I can do that using spanned. But if I used spanned then, I have load images, that will stop working.
Please help me with this.