0
votes

I'm building a Xamarin app that display a webview; currenlty I have my splash screen displayed when the application starts using the code on MainActivity.cs:

[Activity(Label = "App.Xamarin", 
    Icon = "@mipmap/icon", 
    Theme = "@style/Theme.Splash", 
    MainLauncher = true, 
    ConfigurationChanges = ConfigChanges.ScreenSize | ConfigChanges.Orientation)]

Now I need to display the same splash in my webviewrenderer when the webvieb starts/stop to load its content, so I have my own WebViewClient:

internal class CusViewClient : WebViewClient
{
    string _javascript;

    public SistemiWebViewClient(string javascript)
    {
        _javascript = javascript;
    }

    public override void OnPageStarted(Android.Webkit.WebView view, string url, Android.Graphics.Bitmap favicon)
    {
        base.OnPageStarted(view, url, favicon);

        view.Visibility = ViewStates.Invisible;
    }

    public override void OnPageFinished(Android.Webkit.WebView view, string url)
    {
        base.OnPageFinished(view, url);
        view.EvaluateJavascript(_javascript, null);

        view.Visibility = ViewStates.Visible;
    }
}

but I can't find the correct way to display the splash.

1
if you're using XF you could place the splash image over the webview and hide it when the webview loaded the page through the OnNavigated event - FabriBertani
Yep, XF could you please give me an example? I need to reuse my splash code - Irvin Dominin
Could you share the code of the page where you're using the webview first please ? - FabriBertani
Is the following, deadly simple stackoverflow.com/q/58464501/975520 - Irvin Dominin
Check this gist i made to understand better what i'm saying WebViewWithSplashSamplePage.xaml and WebViewWithSplashSamplePage.cs - FabriBertani

1 Answers

0
votes

I ended up using a progress-bar instead of splash screen image to display the progress loading of the page in the chrome client, the code is the following:

    public class CusWebChromeClient : WebChromeClient
    {
        Android.Widget.ProgressBar progressBar;

        public SistemiWebChromeClient(Android.Widget.ProgressBar progressBar)
        {
            this.progressBar = progressBar;
        }

        public override void OnProgressChanged(Android.Webkit.WebView view, int newProgress)
        {
            if (newProgress < 100 && progressBar.Visibility == ViewStates.Gone)
            {
                progressBar.Visibility = ViewStates.Visible;
            }

            progressBar.SetProgress(newProgress, true);

            if (newProgress == 100)
            {
                progressBar.Visibility = ViewStates.Gone;
            }
        }
    }