跟随网址加载的WebView和ActionBarSherlock动态进度条?

时间:2012-08-27 14:46:16

标签: android webview progress-bar android-actionbar

这里来自ABS示例进度条的代码根据网页加载使用ActionBar ProgressBar进行更新,事情是进度条在页面加载之前完成。任何人都可以帮忙更正此代码吗?

private int mProgress = 100;
private Handler mHandler = new Handler();
private Runnable mProgressRunner = new Runnable() {
    @Override
    public void run() {
        mProgress += 1;

        //Normalize our progress along the progress bar's scale
        int progress = (Window.PROGRESS_END - Window.PROGRESS_START) / 100 * mProgress;
        setSupportProgress(progress);

        if (mProgress < 100) {
            mHandler.postDelayed(mProgressRunner, 50);
        }
    }
};

mWebView.setWebChromeClient(new WebChromeClient() {
    @Override
    public void onProgressChanged(WebView view, int progress) {
        if (mProgress == 100) {
            mProgress = 1;
            setSupportProgressBarIndeterminateVisibility(false);
            mProgressRunner.run();
        } else {
            setSupportProgressBarIndeterminateVisibility(true);
        }
    }
});

0 个答案:

没有答案