Share via


Why there is a white screen just before splash screen?

Question

Friday, August 21, 2020 7:49 AM

Hi Everyone, I am creating an splash screen but there is a white screen before splash screen, I don't know why? Here is the code snippet for the same--> SplashScreen-

<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@drawable/binspire">

<ImageView
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_gravity="center"
    android:padding="50dp"
    android:layout_marginTop="90dp"
    android:src="@drawable/inspire_logo"/>

SplashActivity

[Activity(Theme = "@style/MainTheme", MainLauncher = true, NoHistory = true)] public class SplashActivity : AppCompatActivity// global::Xamarin.Forms.Platform.Android.FormsAppCompatActivity// AppCompatActivity { static readonly string TAG = "X:" + typeof(SplashActivity).Name;

    public override void OnCreate(Bundle savedInstanceState, PersistableBundle persistentState)
    {
        base.OnCreate(savedInstanceState, persistentState);
        SetContentView(Resource.Layout.Splash);
        StartActivity(typeof(MainActivity));
        Log.Debug(TAG, "SplashActivity.OnCreate");
        Finish();
    }

MainActivity

[Activity(Label = "InspireApp", Icon = "@mipmap/appicon", Theme = "@@style/MainTheme", MainLauncher = false, ConfigurationChanges = ConfigChanges.ScreenSize | ConfigChanges.Orientation)] public class MainActivity : global::Xamarin.Forms.Platform.Android.FormsAppCompatActivity { protected override void OnCreate(Bundle savedInstanceState) { TabLayoutResource = Resource.Layout.Tabbar; ToolbarResource = Resource.Layout.Toolbar; Rg.Plugins.Popup.Popup.Init(this, savedInstanceState); base.OnCreate(savedInstanceState);

        Xamarin.Essentials.Platform.Init(this, savedInstanceState);
        global::Xamarin.Forms.Forms.Init(this, savedInstanceState);
        LoadApplication(new App());
    }

Please help me to resolve this error.

Thanks

All replies (23)

Friday, August 21, 2020 9:39 AM

there is a white screen just before splash screen Android will load a blank layout before it loads an activity layout based on the theme you have set for it. To fix this issue, try to set android:windowBackground to transparent in the styles.xml.

<style name="MyTheme.Splash" parent ="Theme.AppCompat.Light.NoActionBar"> <item name="android:windowBackground">@android:color/transparent</item> ... </style>

Similar issue: https://stackoverflow.com/questions/30342933/blank-screen-comes-before-splash


Friday, August 21, 2020 10:12 AM

@YelinZh said:

there is a white screen just before splash screen Android will load a blank layout before it loads an activity layout based on the theme you have set for it. To fix this issue, try to set android:windowBackground to transparent in the styles.xml.

<style name="MyTheme.Splash" parent ="Theme.AppCompat.Light.NoActionBar"> <item name="android:windowBackground">@android:color/transparent</item> ... </style>

Similar issue: https://stackoverflow.com/questions/30342933/blank-screen-comes-before-splash

Thanks for the quick reply. I did the same but the issue is still remains. Can you please help me some sample code?


Friday, August 21, 2020 10:21 AM

@YelinZh my problem is I have created a splash layout and I have put it into the layout folder and I want to use that screen as splash screen. How can I use that Splash?


Friday, August 21, 2020 10:38 AM

HAve you take a look to the official Xamarin documentation? There is a page describing splash screen... I have used it and it works


Friday, August 21, 2020 10:43 AM

@AlessandroCaliaro said: HAve you take a look to the official Xamarin documentation? There is a page describing splash screen... I have used it and it works

Yes, I saw that but the documentation contains the splash screen drawable but folder but I have created a layout for splash screen and trying to use that and I am unable to access layout items in styles class.

Any idea?


Friday, August 21, 2020 11:18 AM

Sorry, setting windowBackground to true doesn't seem to work well. Try setting the android:windowDisablePreview to true. I've tested a sample about the code, it works fine. <item name="android:windowDisablePreview">true</item>


Friday, August 21, 2020 12:02 PM

I found that there is a black screen occure before splash screen in your sample. Here is the full code snippet for style, mainactivity, splashactivity and splash.xml..

    <style name="MainTheme" parent="MainTheme.Base">
     </style>
     <!-- Base theme applied no matter what API -->
     <!--<style name="MainTheme.Base" parent="Theme.AppCompat.Light.DarkActionBar">
      --><!--If you are using revision 22.1 please use just windowNoTitle. Without android:--><!--
      <item name="windowNoTitle">true</item>
      --><!--We will be using the toolbar so no need to show ActionBar--><!--
       <item name="windowActionBar">false</item>
       --><!-- Set theme colors from https://aka.ms/material-colors --><!--
       --><!-- colorPrimary is used for the default action bar background --><!--
       <item name="colorPrimary">#2196F3</item>
       --><!-- colorPrimaryDark is used for the status bar --><!--
      <item name="colorPrimaryDark">#1976D2</item>
      --><!-- colorAccent is used as the default value for colorControlActivated
          which is used to tint widgets --><!--
       <item name="colorAccent">#FF4081</item>
       --><!-- You can also set colorControlNormal, colorControlActivated
           colorControlHighlight and colorSwitchThumbNormal. --><!--
      <item name="windowActionModeOverlay">true</item>

       <item name="android:datePickerDialogTheme">@style/AppCompatDialogStyle</item>



    <style name="ActivityTheme" parent ="Theme.AppCompat.Light.NoActionBar">
      <item name="android:windowNoTitle">true</item>
      <item name="android:windowFullscreen">true</item>
      <item name="android:windowContentOverlay">@null</item>
      <item name="android:windowActionBar">true</item>
      <item name="android:windowDisablePreview">true</item>
    </style>
    <style name="AppCompatDialogStyle" parent="Theme.AppCompat.Light.Dialog">
      <item name="colorAccent">#FF4081</item>
    </style>
    </resources>

using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; using Android.App; using Android.Content; using Android.Content.PM; using Android.OS; using Android.Runtime; using Android.Support.V7.App; using Android.Util; using Android.Views; using Android.Widget; //using AndroidX.AppCompat.App;

namespace ABC.Droid { [Activity(Label = "ABC", Theme = "@style/ActivityTheme", MainLauncher = true, NoHistory = true)] public class SplashActivity : Activity { protected override void OnCreate(Bundle savedInstanceState) { base.OnCreate(savedInstanceState);

        SetContentView(Resource.Layout.Splash);

        //StartActivity(new Intent(this,typeof(MainActivity)));

        // Create your application here
    }

    protected override void OnResume()
    {
        base.OnResume();
        Task startupWork = new Task(() => { SimulateStartup(); });
        startupWork.Start();
    }


    async void SimulateStartup()
    {
        await Task.Delay(3000); // Simulate a bit of startup work.
        StartActivity(new Intent(Application.Context, typeof(MainActivity)));
    }
}

}

using System;

using Android.App; using Android.Content.PM; using Android.Runtime; using Android.Views; using Android.Widget; using Android.OS;

namespace InspireApp.Droid { [Activity(Icon = "@mipmap/icon", Theme = "@style/MainTheme", MainLauncher = false, ConfigurationChanges = ConfigChanges.ScreenSize | ConfigChanges.Orientation | ConfigChanges.UiMode | ConfigChanges.ScreenLayout | ConfigChanges.SmallestScreenSize)] public class MainActivity : global::Xamarin.Forms.Platform.Android.FormsAppCompatActivity { protected override void OnCreate(Bundle savedInstanceState) { TabLayoutResource = Resource.Layout.Tabbar; ToolbarResource = Resource.Layout.Toolbar; Rg.Plugins.Popup.Popup.Init(this, savedInstanceState); base.OnCreate(savedInstanceState);

        Xamarin.Essentials.Platform.Init(this, savedInstanceState);
        global::Xamarin.Forms.Forms.Init(this, savedInstanceState);
        LoadApplication(new App());
    }
    public override void OnRequestPermissionsResult(int requestCode, string[] permissions, [GeneratedEnum] Android.Content.PM.Permission[] grantResults)
    {
        Xamarin.Essentials.Platform.OnRequestPermissionsResult(requestCode, permissions, grantResults);

        base.OnRequestPermissionsResult(requestCode, permissions, grantResults);
    }
}

}

<ImageView
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_gravity="center"
    android:padding="50dp"
    android:layout_marginTop="90dp"
    android:src="@drawable/inspire_logo"/>
<!--<ProgressBar
    android:id="@+id/progressBar1"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:background="@android:color/black"
    android:layout_gravity="center_horizontal"/>-->

Friday, August 21, 2020 2:15 PM

I found that there is a black screen occure before splash screen in your sample. That will only occur when debugging the application at the first time.

Try to add the following setting in the styles.xml. <item name="android:windowIsTranslucent">true</item>


Sunday, August 23, 2020 11:12 AM

@YelinZh said:

I found that there is a black screen occure before splash screen in your sample. That will only occur when debugging the application at the first time.

Try to add the following setting in the styles.xml. <item name="android:windowIsTranslucent">true</item>

I am still facing a blank white screen after splash screen.


Sunday, August 23, 2020 11:22 AM

Maybe this will help: http://web.archive.org/web/20180526144705/https://plus.google.com/+AndroidDevelopers/posts/Z1Wwainpjhd


Sunday, August 23, 2020 11:28 AM

@Exoskeletor said: Maybe this will help: http://web.archive.org/web/20180526144705/https://plus.google.com/+AndroidDevelopers/posts/Z1Wwainpjhd

I did that but i want to do that with the Layout. Any idea?


Monday, August 24, 2020 9:35 AM

a sample file which works fine. Try to test it on your side to check if it works. If it doesn't work, please share a basic demo to reproduce the issue.


Tuesday, August 25, 2020 4:19 AM

@YelinZh said: I posted a sample file which works fine. Try to test it on your side to check if it works. If it doesn't work, please share a basic demo to reproduce the issue.

Sure, I will do the same.


Tuesday, August 25, 2020 9:09 AM

Waiting for your update.


Wednesday, August 26, 2020 7:54 AM

@YelinZh said: Waiting for your update.

I tried your solution everything works fine but there is an transparent area at the edge of the splash screen header. How can I remove that?


Wednesday, August 26, 2020 8:19 AM

I tried your solution everything works fine but there is an transparent area at the edge of the splash screen header. It works fine on my side, see as shown. Try to remove the below setting in the style.xml. <item name="android:windowIsTranslucent">true</item> !


Wednesday, August 26, 2020 9:03 AM

@YelinZh I have attached the demo project you can reproduce the error. Still a white screen.


Thursday, August 27, 2020 6:04 AM

demo and it works also well.

!

The issue should be not caused by the splash screen, instead the main page may takes a long time to be loaded. Try to use a simple contentPage for test to check that.


Thursday, August 27, 2020 6:31 AM

@YelinZh said: I test the posted demo and it works also well.

!

The issue should be not caused by the splash screen, instead the main page may takes a long time to be loaded. Try to use a simple contentPage for test to check that.

Okay I will try and let you know.


Friday, August 28, 2020 12:21 PM

Waiting for your update.


Saturday, August 29, 2020 4:52 AM

@YelinZh said: Waiting for your update.

Here is a screen record which will show a white screen after splash screen. I have have added a different page and navigate to it from app.xaml.cs.


Monday, August 31, 2020 2:31 PM

Here is a similar issue case, hope it'll help you. https://stackoverflow.com/questions/61596142/xamarin-forms-a-flash-of-white-screen-after-splashscreen-android


Tuesday, September 1, 2020 11:59 AM

@YelinZh said: Here is a similar issue case, hope it'll help you. https://stackoverflow.com/questions/61596142/xamarin-forms-a-flash-of-white-screen-after-splashscreen-android

Okay, Thanks