How can I copy all visible text of a webView? - android

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.

Related

Inverse/Reverse of Html.fromHtml(String)

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.

Android - Questions about Edit Text in WebView

I'm using a Edit Text to put in a URL to search in the Internet. But to use a URL, I need to put http:// in front of the Url. Is there a way, to hide this and use it for default?
And the other thing is to have only one single line in the Edit Text?
Thanks
Is there a way, to hide this and use it for default?
When you retrieve the value from the EditText, see if it begins with a recognized scheme (e.g., https://). If not, add it yourself, through string concatenation or StringBuilder or something.
And the other thing is to have only one single line in the Edit Text?
Use android:maxLines="1" in the <EditText> element in your layout.

How do I keep the text from changing color when a link in html in a webview is clicked? (Android)

I have almost no experience with html and am only using a WebView to load a local Word doc converted to html that serves as the FAQ in my app. Items in the table of contents can be clicked to jump to a FAQ item.
Currently the table of contents links turn purple when they've been clicked. Can I turn off this behavior so that the links stay blue?
If web view is navigating to website that you own, then you can change its CSS like
a:visited{
color : #0000FF;
}
else you can't change its color.

Android: How to copy one word from a block of texts to search for definition

I am developing an Android application and I have displayed a story using TextView. I want that if the user tap on a particular word, it will copy that word and send it to the dictionary within the application and search for its definition. How do I do that? How do I know what word is tapped by the user since the TextView consists of around hundred words.
In same case I used array of textViews. To make it this way you should prepare text, for example split text with " ".
The second way is to use WebView, text as html doc and some javascript.

Android Get url of hyperlink clicked from TextView' text

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.

Categories

Resources