Xamarin.forms Splashscreen (Android) 后出现白屏闪烁

And*_*vil 0 xamarin.android xamarin xamarin.forms

这个问题已在 SO 和 xamarin.forums 上多次被问到。但我无法解决这个问题。

在我的 xamarin.forms android 应用程序中,我有一个启动画面。它完美启动。问题是在加载我的主页和启动画面之间,会出现白屏闪烁。我遵循了https://xamarinhelp.com/creating-splash-screen-xamarin-forms/ 中的教程。

我尝试通过为启动画面创建特定活动并将启动主题直接设置为 MainActivity。两种方式我都无法摆脱白屏闪烁。我在发布模式下尝试过,问题仍然存在。这是使用 xamarin 的预期行为吗?我怎样才能删除它?任何帮助表示赞赏。

我的主要活动

   [Activity(Label = "SampleApp", Icon = "@mipmap/ic_launcher", Theme = "@style/splashscreen", ScreenOrientation = ScreenOrientation.Portrait, MainLauncher = true, LaunchMode = LaunchMode.SingleTop, ConfigurationChanges = ConfigChanges.ScreenSize | ConfigChanges.Orientation)]
    public class MainActivity : global::Xamarin.Forms.Platform.Android.FormsAppCompatActivity
    {
        static readonly string TAG = "MainActivity";
        protected override void OnCreate(Bundle savedInstanceState)
        {
            TabLayoutResource = Resource.Layout.Tabbar;
            ToolbarResource = Resource.Layout.Toolbar;           
            global::Xamarin.Forms.Forms.SetFlags("CollectionView_Experimental");
            base.SetTheme(Resource.Style.MainTheme);
            base.OnCreate(savedInstanceState);

        }           
}
Run Code Online (Sandbox Code Playgroud)

Init()在 MainActivity 中有几个库,这里不包括在内。

我的 App.Xaml.cs

 public partial class App : Application
    {

        public App()
        { 
                var Login = new NavigationPage(new LoginPage());
                MainPage = Login

        }
        protected override void OnStart()
        {            
        }

        protected override void OnSleep()
        {
            // Handle when your app sleeps
        }

        protected override void OnResume()
        {
            // Handle when your app resumes
        }
    }
Run Code Online (Sandbox Code Playgroud)

我的风格

<style name="splashscreen" parent="Theme.AppCompat.Light.NoActionBar">
    <item name="android:windowBackground">@drawable/Splash</item>
    <item name="android:windowNoTitle">true</item>
    <item name="android:windowIsTranslucent">false</item>
    <item name="android:windowIsFloating">false</item>
    <item name="android:backgroundDimEnabled">true</item>  
  </style>

  <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 http://www.google.com/design/spec/style/color.html#color-color-palette -->
    <!-- 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>
     <item name="android:backgroundDimEnabled">true</item>
    <!-- colorAccent is used as the default value for colorControlActivated
         which is used to tint widgets -->
    <item name="colorAccent">#FF4081</item>

    <item name="android:textAllCaps">false</item>
    <!-- You can also set colorControlNormal, colorControlActivated
         colorControlHighlight and colorSwitchThumbNormal. -->
    <item name="windowActionModeOverlay">true</item>

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

  <style name="AppCompatDialogStyle" parent="Theme.AppCompat.Light.Dialog">
    <item name="colorAccent">#FF4081</item>
  </style>
Run Code Online (Sandbox Code Playgroud)

我的可绘制/飞溅

<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
  <item>
    <color android:color="@color/splash_background"/>
  </item>
  <item>
    <bitmap
        android:src="@drawable/Logo"
        android:tileMode="disabled"
        android:gravity="center"/>
  </item>
</layer-list>
Run Code Online (Sandbox Code Playgroud)

Wil*_*gas 8

尝试将其添加到您的样式中:

<item name="android:windowAnimationStyle">@null</item>
Run Code Online (Sandbox Code Playgroud)

像这样:

<item name="android:windowAnimationStyle">@null</item>
Run Code Online (Sandbox Code Playgroud)

我建议使用 SplashActivity.cs 并添加

AddFlags(ActivityFlags.NoAnimation); 
Run Code Online (Sandbox Code Playgroud)

像这样:

<style name="splashscreen" parent="Theme.AppCompat.Light.NoActionBar">
    <item name="android:windowBackground">@drawable/Splash</item>
    <item name="android:windowNoTitle">true</item>
    <item name="android:windowIsTranslucent">false</item>
    <item name="android:windowIsFloating">false</item>
    <item name="android:backgroundDimEnabled">true</item>
    <item name="android:windowAnimationStyle">@null</item> //Add this line
</style>
Run Code Online (Sandbox Code Playgroud)