且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

在 android 应用程序的 webview 中加载 url 时的启动画面

更新时间:2023-01-25 22:15:08

我首先显示一个 ImageView,然后在 WebView 加载后,像这样交换它们的可见性

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");

我的 xml 布局是这样的

And my xml layout looks like this

    <ImageView android:id="@+id/imageLoading1"
        android:layout_height="fill_parent"
        android:layout_width="fill_parent"
        android:visibility="visible"
        android:src="@drawable/vert_loading"
        />
    <WebView android:id="@+id/webView1"
        android:layout_height="fill_parent"
        android:layout_width="fill_parent"
        android:visibility="gone"
        />