Android: web view loading process dialog

 

when open a web it will show how much will it load.

 

 

 

 

 

package com.mapking.cube;

 

 

private int mProgress = 0;

private static final int MAX_PROGRESS = 100;

private static final int DIALOG_PROGRESS = 4;

 

private String link = "http://www.baidu.com";

 

    private ProgressDialog mProgressDialog;

    private WebView webview;

 

@Override

protected void onCreate(Bundle savedInstanceState) {

// TODO Auto-generated method stub

 

super.onCreate(savedInstanceState);

showDialog(DIALOG_PROGRESS);

 mProgress = 0;

 

getWindow().requestFeature(Window.FEATURE_PROGRESS);

webview = new WebView(this);

webview.getSettings().setJavaScriptEnabled(true);

        webview.loadUrl(link);        

 

        webview.setWebViewClient(webViewClient);

        webview.setWebChromeClient(webChromeClient);

        setContentView(webview);

}

 

private WebViewClient webViewClient = new WebViewClient(){

        @Override

        public boolean shouldOverrideUrlLoading(WebView view, String url) {

            view.loadUrl(url);

            return true;

        }

    };

 

    private WebChromeClient webChromeClient = new WebChromeClient(){

     public void onProgressChanged(WebView view, int progress){

 

     mProgress = progress;

     mProgressDialog.setProgress(mProgress);

     Log.e("xxxx", "progress: "+progress);

    

     if (mProgress >= MAX_PROGRESS) {

                mProgressDialog.dismiss();

            }

     }

    };

 

 

 

    @Override

    protected Dialog onCreateDialog(int id){

     switch (id){

     case DIALOG_PROGRESS:

            mProgressDialog = new ProgressDialog(CubeSideActivity.this);

            mProgressDialog.setIcon(R.drawable.mapking);

            mProgressDialog.setTitle("Connect to Server...");

            mProgressDialog.setProgressStyle(ProgressDialog.STYLE_HORIZONTAL);

            mProgressDialog.setMax(MAX_PROGRESS);

 

            return mProgressDialog;

     }

     return null;

    }

 

 

 

@Override

protected void onPause() {

// TODO Auto-generated method stub

webview.stopLoading();

super.onPause();

}

 

 

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值