Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to show a loading bar when rendering with Webview.loadUrl in android?

Tags:

When using webview to show html pages,

there will be several seconds of blank page before it finished rendering.

For better user experience, is there a way to make it show a loading image during that several seconds?

like image 317
new_perl Avatar asked Feb 27 '12 11:02

new_perl


People also ask

How do I display HTML content in WebView?

Step 1 − Create a new project in Android Studio, go to File ⇒ New Project and fill all required details to create a new project. Step 2 − Add the following code to res/layout/activity_main. xml. In the above code, we have taken web view to show html content.

Which method from the WebView class loads a web page in Android?

The loadUrl() and loadData() methods of Android WebView class are used to load and display web page.

Is Android WebView deprecated?

This interface was deprecated in API level 12. This interface is now obsolete.


1 Answers

Try this

        ......          webView.setWebChromeClient(new WebChromeClient() {            public void onProgressChanged(WebView view, int progress) {               activity.setTitle("Loading...");               activity.setProgress(progress * 100);                if(progress == 100)                  activity.setTitle(R.string.app_name);            }         });         ... 
like image 89
Vyacheslav Shylkin Avatar answered Oct 05 '22 04:10

Vyacheslav Shylkin