android片段webview加载指标

时间:2013-07-28 00:33:34

标签: android eclipse screen splash

我想在我的webview中添加加载指示器是否有任何解决方案?

提前谢谢!!

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 {

    }
}

1 个答案:

答案 0 :(得分: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);ProgressBar设置webview 1}}首先加载。要在内容加载完成后停止进度视图,您可以创建新的WebChromeClient并添加OnProgressChanged,并在进度达到100%时将ProgressBar的可见性设置为false < / p>