1

I would like to add loading indicator to my webview is there any solution for it?

thank you in advance!!

import com.actionbarsherlock.app.SherlockFragment;

public class Showing_now extends SherlockFragment{

    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    View mainView = (View) inflater.inflate(R.layout.activity_showing_now, container, false);
    WebView webView = (WebView) mainView.findViewById(R.id.webViewsn);

    webView.setWebViewClient(new MyWebViewClient());
    webView.getSettings().setPluginsEnabled(true);
    webView.getSettings().setBuiltInZoomControls(false); 
    webView.getSettings().setSupportZoom(false);
    webView.getSettings().setJavaScriptCanOpenWindowsAutomatically(true);   
    webView.getSettings().setAllowFileAccess(true); 
    webView.getSettings().setDomStorageEnabled(true);
    webView.getSettings().setJavaScriptEnabled(true); 
    webView.getSettings().setPluginState(PluginState.ON);
    webView.loadUrl("http://www.myweburl.com");
    return mainView;
}
    private class MyWebViewClient extends WebViewClient {

    }
}
4

1 回答 1

2

如果您使用的是 ActionbarSherlock 和 Android 支持库,我建议使用此设置

protected void onCreate(Bundle savedInstanceState) {
    requestWindowFeature(Window.FEATURE_PROGRESS);
    super.onCreate(savedInstanceState);
    setContentView(R.layout.webview);
    setSupportProgressBarVisibility(true);
    WebView mWebView = (WebView) findViewById(R.id.WebView);
    mWebView.setWebChromeClient(new WebChromeClient() {
        public void onProgressChanged(WebView view, int progress) {
            setSupportProgress(progress * 100);
            if (progress == 100) {
                setSupportProgressBarVisibility(false);
            }
        }
    });
    webView1.loadUrl("http://www.google.com");
}

非常多,您只需要requestWindowFeature(Window.FEATURE_PROGRESS)在设置之前调用,然后在第一次加载时ContentView用于setSupportProgressBarVisibility(true);设置ProgressBaron create 。webview要在您的内容完成加载时停止 progressview,您将创建一个新的WebChromeClient并添加OnProgressChanged并将ProgressBar的可见性设置为 false 每当进度达到 100%

于 2013-07-28T00:36:11.357 回答