Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
412 views
in Technique[技术] by (71.8m points)

android - How to make a WebView Load fast And adding a Progress bar to it

I am making a simple application in which I have put a webview, but the page is loading very slow(tried with many websites) and also I want to add a progress bar so it should show that the page is loading. Here is the code I am using for webview but I have no idea how to get progress bar on it:

public class MainActivity extends Activity {

WebView wv;
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);

    wv = (WebView) findViewById(R.id.webView1);
    wv.setWebViewClient(new webCont());

    wv.loadUrl(" http://www.abc.com" ); 
}
 class webCont extends WebViewClient
{

    @Override
    public boolean shouldOverrideUrlLoading(WebView view, String url) {
        // TODO Auto-generated method stub
        view.loadUrl(url);

        return true;
    }
}
See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

Set webview on WebChromeClient() and try this code

    ProgressDialog progressDialog = new ProgressDialog(this);  
    progressDialog.setMessage("Loading Data...");  

    webview.setWebChromeClient(new WebChromeClient() {
        public void onProgressChanged(WebView view, int progress) {

            if (progress < 100) {
                progressDialog.show();
            }
            if (progress == 100) {
                progressDialog.dismiss();
            }
        }
    });

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

2.1m questions

2.1m answers

60 comments

57.0k users

...