I have html string. I need to show my it in my TextView. Here is my code:
tvText.setText(Html.fromHtml(htmlString));
Html string contains some text, but may also contains links. I need to detect if a string contains a link, make part of that string clickable.
I can do a search for links in a string myself and then use SpannableString and ClickableSpan.
But perhaps there is some way to set a click in html and then the mobile application will be able to react for some reason and make part of the string clickable.
Please help me.
UPD: I can request an html string in any form, so I need to understand what it should be in order to process a click in a mobile application without any search for links in string.
Try to wrap your links in html <a> tags and set movement method to your textView like this:
textView.setText(Html.fromHtml("This is a link"));
textView.setMovementMethod(LinkMovementMethod.getInstance());
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 am creating a note application for myself. To style my notes, I write html tags, click a button and show styled version with html. from html.. But the problem is, I need to store the text with html tags not without it so when I get the data from the database, I get the text with style.
So I wonder is there any way to decode embedded html tags other than storing the string before html. from html function and acting accordingly? Also i can click the button anytime then continue typing which is very hard to track. Because i run this function to stylize ;
text.setText(Html.fromHtml(text.getText().toString()));
Which means i lose the tag info.
Thanks in advance.
If the user of the app write the html tags, the app should store them.
So as you suggest yourself, you will have to store the string before calling Html.fromHtml.
I have text like this: "by proceeding you agree to our terms of service"
I want "terms of service" to be underlined and link to a certain website. Is there a way to do this in xml? I know about the autolink property, but seems to only work if you want to link a text that actually is the url it self. I want to turn any piece of text into a web hyperlink.
if not possible to do it through xml, what's quickest (yet still correct) way to do it through code?
Thanks
Firstly use two textviews and align it side by side. In place of link you can place any web address and apply this snippet on your textview
textView.setClickable(true);
textView.setMovementMethod(LinkMovementMethod.getInstance());
String text = "<a href='http://www.google.com'> Google </a>";
textView.setText(Html.fromHtml(text));
I've searched the Internet for a solution but I can't find it.
I have a WebView that display text, Just text. I want to wrap the text in the WebView, is that possible, or what?
And I want to make the user be able to select a certain text in the WebView and make him able to send the selected text by SMS, is that possible to?
I found the solution. You have to add some div tag on your web document, and then add a css class. I did this:
<div class="wrap">
with a css class like this:
.wrap {
word-wrap:break-word;
}
If the content in the WebView is something that you yourself have created or have control of, use a stylesheet optimized for mobile devices, or you can use jTouch or jQuery Mobile
If your content is literally plain text (no HTML markup), then the WebView will be treating it as preformatted text and won't wrap or insert linebreaks.
Try wrapping your text in an HTML wrapper:
<html><body>My text goes here</body></html>
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.