How to edit content and layout of webview? - android

Is there a way for me to edit the contents of the Webview or to crop out some parts of the content, i'm focusing on UI and would like to clean up the content for a project i am working on.
Also lets say I want to display content of the webView individually as well (multiple webviews within an activity) for aesthetic purposes, how would I go about doing that?

One technique I've used in the past is to request the page with an HttpURLConnection rather than the WebView. Then I parse and edit the HTML data and display it in the WebView using the loadData method. You could even use something like JSoup to parse the HTML. However, if you are depending on having the JavaScript run on the page, you may have a problem because using loadData will disrupt the same-origin policy.

Related

Why do most news reading app like Pocket, Instapaper, Google Play Newsstand or NYTimes display articles as natives components instead of WebView?

I used the android device monitor to check different News Reader UI and I realized that almost all of them are using Native components (ImageView, TextView, FrameLayout) to display their article instead of a WebView. I was wondering what could have motivated such a choice ?
A webService could return the article with a property containing the extracted and formatted html then the webView could be loaded from this plain html String with java webView.loadData("<div></di>", .., ..) right?
Rendering a webview is slower than calling a web service . If you render webview it will load a whole lot component like css, javascript . But If you call web service , you will only get the data you want and then populate other component like textview , image view etc with .

Preloading web page in Android (using WebView?)

I want to pre load a web page in Android. The web page contains both text and graphical elements. The web page will be displayed in the future in an Activity which has not been created yet.
As far I understand it a WebView for example has to be tied to an Activity, thus it's not possible to use a WebView for this task.
Anyone got any suggestions which does not involve parsing the html page and downloading all the elements "manually"?
According to android's documenation: For obvious security reasons, your application has its own cache, cookie store etc.—it does not share the Browser application's data.
So we can make use of the above info in a smart way by doing this:
Whenever you want to start loading your website, create a new WebView object and request the url from it. the code will look something like this:
WebView view = new WebView(context);
view.loadUrl(myBigWebSite);
Android will cache that webview data and when you request loadUrl from another activity it should be already loaded.
// in your WebView activity
myWebView.loadUrl(myBigWebSite);
For more about webViews visit the documentations page : WebView doc
You can download all required files (images, etc) into some folder on a network thread and then use something like
webview.loadUrl("file:///my_cached_folder/index.html");
Images will also be picked from this folder, if referenced and present. Read about opening local files on webview here.

Which one is better between TextView or WebView?

Currently I'm about to display HTML data into my application with fragment. I'm confused of which one I need to use to get better performance between TextView or WebView. I mean, for rendering speed and memory issue.
Know that Html.fromHtml() is available for TextView to display HTML formatted data but I want to try WebView instead of TextView. But don't know rendering speed and memory issue.
WebView internally provides different functionality for the display Html data. Also you can use JavaScript in WebView.
While TextView when you are use Html.fromHtml() then its support only few Html tags.
So I think its better to use WebView.
I just mentioned JavaScript functionality but There are other functionality like (Zoom Functionality, Image from web, etc..) All supports in WebView.
depends for what you wish to use it.. if you are loading website and want all the features of that website to be available you should use webview. If you are only displaying one html snippet you should use textview

How do you make a textview change according to an HTML document on the web

A couple of friends and I are setting up a little app business, and we are creating our general app for finding out all the latest news about our other apps. But we have a small problem.
We have a layout xml file with a table row in it. In the table row we want to show two textviews. One that says Current App version (Which we have done successfully) and the other one will show a few numbers from an HTML page which is live now.
I want to know, how would be able to get the text from the HTML document on the Web to that text view, or any other thing we could use.
(We know that the manifest will have to allow the internet)
Thanks
So in this TextView, you want to show the content of the HTML page? If this is the case, the best thing you could do is to replace the TextView with a WebView, where you could load the HTML page via its url.
If not this is the case, you can make a GET request to that HTML (i.e. using an Async Task), get the results and present them in the TextView.
Hope this helps!

Can WebView be used for HTML parsing?

I came across the WebView class in android.webkit and was impressed by how it "does everything for you" (as a programmer), as far as rendering visual HTTP content on the screen.
My question: Is it possible to use the WebView class as a shortcut for parsing rendered HTML for non-visual purposes?
(that is, retrieve certain elements from a web page for text processing, etc.)
If so, how would one go about this?
You don't need to, as far as I know, Android is using TagSoup to parse HTML, and you can use it too.

Categories

Resources