Splash screen while loading a url in a webview in android app

前端 未结 3 506
名媛妹妹
名媛妹妹 2020-11-30 22:01

I\'ve got an app, that has 2 activity, the first one launch the second to load a url into a webview.

It works, but while the url is loading , the webview appear empt

3条回答
  •  佛祖请我去吃肉
    2020-11-30 22:36

    I do it by initially showing an ImageView and then once the WebView has loaded, swapping their visibility like this

            WebView wv = (WebView) findViewById(R.id.webView1);
            wv.getSettings().setJavaScriptEnabled(true);
            wv.setWebViewClient(new WebViewClient() {
    
                ...
    
                @Override
                public void onPageFinished(WebView view, String url) {
                    //hide loading image
                    findViewById(R.id.imageLoading1).setVisibility(View.GONE);
                    //show webview
                    findViewById(R.id.webView1).setVisibility(View.VISIBLE);
                }
    
    
            });     
            wv.loadUrl("http://yoururlhere.com");
    

    And my xml layout looks like this

        
        
    

提交回复
热议问题