Stop WebView rendering until the page is fully-loaded - android

I'm working on an app that is using WebView. Unfortunately, when user clicks a link, when the page is loading, the whole WebView area "blinks" until its loading is complete. There's also 1 more problem with it - I'm using a JavaScript that reverses colors of the page at the end of its loading - so until it's fully-loaded, the colors are normal, so again - blinking.
So, what I wannna do is "stop" rendering of the WebView, until the page is completely loaded - then, resume the rendering, so it won't blink. How to do that?
Note: I don't want to modify the webpage to achieve what I want. I have to modify WebView behavior.
And one more note, because it's maybe not clear: by "stop rendering" I mean "display currently rendered page continually until the new one is fully loaded" :)

First make your layout background color white then make the WebView invisible.
after this use AsyncTask then put your webview loading in doInBackground and when it's finished in onPostExecute make your webview visible.
so the user will see the white layout first then the visible webview after fully loaded in postexcute
sorry if my english not good

You could implement a custom WebView, and override it's invalidate() method to do nothing until the page is fully loaded.

Related

android webview display is delayed

I got an Acivity holding a WebView displayed on the screen right when it get turned on. The WebView itself is already loaded before. I expect the WebView to be displayed with the rest of the Activity, but instead it is delayed by half a second, so I got a big hole in my layout for this half second.
This happen only the first time the view is displayed after been created.
I do not want the activity to be visible while the WebView isn't, but I cannot find anything telling me when the WebView is avalaible. I tried with getDrawingRect and such, but their values are still been changed before the WebView is visible.
Is it possible to know exactly when a WebView is displayed, or even to erase that delay?
Thanks for your help.

Android: get screenshot from hidden WebView every new page redraw

New to Android programming. I need to develop an app getting screenshot of a webpage every time something change inside it. My first way was to extend WebView class and overrite onDraw() call. This allow me to know when web page change by get redraw request and take new screenshot. The problem is, obviously, onDraw is called only if the WebView control is currently visibile on the view but in my case I need to keep it hidden since I want to use only the webkit engine in background and show in the interface only the screenshot of the current page. If I keep hide the WebView no redraw event is delivered. So my question is if there is a way to make what I need? (hope to explained well my problem). Please note, "keep hide" mean I don't put the WebView control inside the layout interface but create separately by using something like "new WebView(this)" at app startup.
Thank you
Just render to a bitmap as these guys did: Converting a view to Bitmap without displaying it in Android?
Override onPageFinished and draw the view in there.

Android: setVisibility(View.GONE) reducing the font size and image size on the webview

I have an android application that hits the WebView and displays the content. But as per the requirement initially I should hide the WebView and later on I should show it to the user.
So, initially I call setVisibility(View.GONE); and hide the visibility of the WebView. And, then I call setVisibility(View.VISIBLE); to show the WebView to the user.
1)When I am doing in this sequence, the size of the content(font and images) on the WebView are getting reduced.
2)If I don't call setVisibility(View.GONE); and directly show it to the user then size of the content(font and images) on the WebView is bigger.
I want to achieve 2 scenario by initially hiding the WebView. Means I want to hide the WebView initially, and then show to the user with bigger sized content on WebView.
How do I achieve this?
I have got this working finally!!!
Instead of using setVisibility(View.GONE); to make the webview invisible, I am using setVisibility(View.INVISIBLE);.
This way I was able to achieve the proper size of items on the webview. Dont know the exact reason for this mismatch, but it is working as expected with this change.
I can't tell just how much the sizes are changing, but have you tried using WebView.zoomIn/WebView.zoomOut? You can also set the default with WebView.getSettings().setDefaultZoom.

How to show loading icon in webview when we flip throug webviews in android

Actually my app hase 3 webviews and we can flip through it. I had added a loading progress bar on each webview. Now when i start the app, first web view loads. I am not able to flip the views as loading symbol is in foreground. My requirement is, webview have to show loading symbol until it loads as well as it can be flipped to other webviews which again have loading symbol.
I am tired of trying everything but not able to do it. Please anyone have any solution.
Thanks in advance....
We can't do anyting when loading symol comes.we have to cancel it by back button for doing anything else. I had solved this by creating a progress bar in XML and doing a logic for making it visible and invisible according to requirement.

WebView, Splash Screen and performance

I've got WebView within an Activity that loads content from the network. When the WebView starts loading I launch another activity to act as a Splash Screen that I hide when the WebView is done loading.
I found out when testing that the same web page takes longer to load when I add a splash screen than when I don't. So I assume there's a network thread whose priority drops when the activity containing the WebView goes to the background. How do I control that thread to keep the WebView fast?
I found the setRenderPriority method of the WebSettings class, I'm not sure what it does and I don't know what is the "Render thread" it talks about. I tried :
getSettings().setRenderPriority(WebSettings.RenderPriority.HIGH);
but it didn't have any effect on the loading time.
Thanks to anyone who can help me out.
I'm not directly answering your question, but rather suggesting an alternative... starting another activity to simply provide a splash screen could be rather expensive. Instead, you might consider extending the layout that contains your WebView to place a RelativeLayout at the WebView's level, and make your WebView a child of that layout. Additionally, you can place an ImageView (or whatever you need for your splash) within the same RelativeLayout, and you can set its visibility to invisible when you don't want it displayed.

Categories

Resources