在 android 应用程序的 webview 中加载 url 时的启动画面 [英] Splash screen while loading a url in a webview in android app

查看:26
本文介绍了在 android 应用程序的 webview 中加载 url 时的启动画面的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个应用,它有 2 个 Activity,第一个启动第二个以将 url 加载到 webview 中.

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

它可以工作,但是当 url 正在加载时,webview 显示为空...然后我想制作一个启动画面或类似的东西,在 url 加载时显示它,我在一个新的活动中做到了这一点,但我不知道在加载 url 时我该怎么做才能关闭第三个活动...请有人帮我吗?

It works, but while the url is loading , the webview appear empty... then i want to make a splash screen or something like this, to show it while the url is loading, I did that in a new activity, but i don't know what can i do to close the third activity when the url is loaded... Please can anybody help me?

这是我的代码...谢谢!

This is my code...Thank you!

public class Visor extends  Activity {

    WebView mWebView;
    int Result;

    @Override
    public void onCreate (Bundle savedInstanceState){
        super.onCreate(savedInstanceState);
        setContentView(R.layout.visor);
        Bundle extras=getIntent().getExtras();
        String s= extras.getString("url");

        mWebView = (WebView) findViewById(R.id.webview);
        mWebView.getSettings().setJavaScriptEnabled(true);
        mWebView.getSettings().setPluginsEnabled(true);
        mWebView.getSettings().setAllowFileAccess(true);

        mWebView.loadUrl(s);
        mWebView.setWebViewClient(new VisorClient());
        mWebView.getSettings().setBuiltInZoomControls(true);

        }

    private class VisorClient extends WebViewClient {

            @Override
            public void onPageStarted(WebView view, String url, Bitmap favicon) {
                lanzarIntro();
            }
            @Override
            public void onPageFinished(WebView view, String url) {
                mWebView.loadUrl(url);
            }
     }

    public void lanzarIntro(){
        Intent i=new Intent (this, Intro.class);

        startActivity(i);


    }



}

推荐答案

我首先显示一个 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"
        />

这篇关于在 android 应用程序的 webview 中加载 url 时的启动画面的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆