我在启动我的应用程序时加载webview

时间:2016-04-29 08:55:35

标签: java android android-studio

我正在启动应用程序时加载Web视图。 但在此之前我正在加载启动画面,我想显示启动画面,直到Web视图完全加载。 我怎样才能做到这一点? 我在Android Studio工作。

3 个答案:

答案 0 :(得分:2)

使用webview客户端

加载网页时,可以隐藏启动画面
 mWebView.setWebViewClient(new WebViewClient() {

   public void onPageFinished(WebView view, String url) {
        // hide your splash screen
    }
});

答案 1 :(得分:0)

这样做......

  public class SItemsWebView extends ActionBarActivity {
        private WebView webView;   
        private String url;


        @Override
        protected void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
            setContentView(R.layout.activity_show_subject_list_items_in_web_view);
            this.initViews();      
            loadWebView(url);
             }

        //initializes all views
        private void initViews() {
            webView = (WebView) findViewById(R.id.filesWebView);
        }   

        //show Url in WebView
        public class myWebClient extends WebViewClient {
            @JavascriptInterface
            @Override
            public void onPageStarted(WebView view, String url, Bitmap favicon) {
                // TODO Auto-generated method stub
                super.onPageStarted(view, url, favicon);
               //show your splash scree here
            }

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

            @Override
            public void onPageFinished(WebView view, String url) {
                // TODO Auto-generated method stub
                super.onPageFinished(view, url);
                // hide your splash image here
                }
            }
        }


        public void loadWebView(String url) {
            webView.setWebViewClient(new myWebClient());
            webView.getSettings().setJavaScriptEnabled(true);
            webView.getSettings().setBuiltInZoomControls(true);
            webView.getSettings().setUseWideViewPort(true);
            webView.getSettings().setLoadWithOverviewMode(true);                
            webView.setVisibility(View.VISIBLE);
            webView.loadUrl(url);
        }               

    }

答案 2 :(得分:0)

试试这个,

mWebView.setWebViewClient(new WebViewClient() {

        public void onPageStarted(WebView view, String url, Bitmap icon) {
            // TODO Auto-generated method stub
            super.onPageStarted(view, url, icon);
            //show your splash scree here
        }

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

        public void onPageFinished(WebView view, String url) {
            // hide your splash screen
        }
    });