Jay Smoke
Jay Smoke

Reputation: 604

Fade out splashscreen, fade in webview in android

Am currently using the code below to switch between my splashscreen and my webview. It works fine except that the switch is abrupt and not really elegant. What I want to know is how to make the splash screen fade away when content is loaded and the webview fadein instead?

here is my working code;

@Override
            public void onPageFinished(WebView view, String url) {
            //hide loading image
            findViewById(R.id.imageLoading1).setVisibility(View.GONE);
            //show webview
            findViewById(R.id.webview).setVisibility(View.VISIBLE);
        }

Thank you.

Upvotes: 2

Views: 1339

Answers (1)

Siros Baghban
Siros Baghban

Reputation: 406

Use this :

private ImageView splash; 
splash = (ImageView) findViewById(R.id.SplashId);
        webview = (WebView) findViewById(R.id.WebviewId);

        webview.setVisibility(View.GONE);
        splash.setVisibility(View.VISIBLE);

        final Animation fadeIn = new AlphaAnimation(0, 1);
        fadeIn.setInterpolator(new DecelerateInterpolator());
        fadeIn.setDuration(1000);
        final Animation fadeOut = new AlphaAnimation(1, 0);
        fadeOut.setInterpolator(new AccelerateInterpolator());
        fadeOut.setStartOffset(1000);
        fadeOut.setDuration(1000);
        final AnimationSet animation = new AnimationSet(false);
        animation.addAnimation(fadeIn);
        animation.addAnimation(fadeOut);

    webview.setWebViewClient(new WebViewClient() {
    @Override
    public void onPageFinished(WebView view, String url) {

        splash.setAnimation(fadeOut);
        splash.postDelayed(new Runnable() {
                @Override
                public void run() {
                    splash.setVisibility(View.GONE);
                    webview.setVisibility(View.VISIBLE);
                    webview.setAnimation(fadeIn);
                }
            }, 1600);
        }


});

Gone Splash [FadeOut] And then, Visible WebView [FadeIn] by Animation. Enjoy :)

Upvotes: 4

Related Questions