首页 > 解决方案 > Xamarin 在启动画面后形成 10 秒黑屏

问题描述

一开始我应该说我已经阅读了所有类似的问题,但它们无法解决我的问题。

我的 Xamarin Forms 项目中有一个启动画面,并检查其中的凭据,然后在每个条件下启动 Main Activity,并针对条件使用不同的参数。当启动画面完成它的工作并消失时,应用程序显示黑屏大约 10 秒,然后显示主页

这是我的飞溅:

[Activity(Theme = "@style/MainTheme.Splash",
              MainLauncher = true,
              NoHistory = true,
              ScreenOrientation = ScreenOrientation.Portrait)]
    public class SplashActivity : Activity
    {
        static readonly string TAG = "X:" + typeof(SplashActivity).Name;
        public override void OnCreate(Bundle savedInstanceState, PersistableBundle persistentState)
        {
            base.OnCreate(savedInstanceState, persistentState);
            Xamarin.Essentials.Platform.Init(this, savedInstanceState);
            Log.Debug(TAG, "SplashActivity.OnCreate");
        }

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

        async void SimulateStartup()
        {
            Some Code ...
            InvokeMainActivity("SomeType");
        }

        private void InvokeMainActivity(string type)
        {
            Intent _activity = new Intent(Application.Context, typeof(MainActivity));
            _activity.PutExtra("Key", type);
            _activity.AddFlags(ActivityFlags.NoAnimation);
            StartActivity(_activity);
        }

这是我的 MainActivity :

[Activity(Label = "@string/app_name",
        Icon = "@drawable/icon",
        Theme = "@style/MainTheme",
        MainLauncher = false,
        LaunchMode = LaunchMode.SingleTask,
        ConfigurationChanges = ConfigChanges.Orientation | ConfigChanges.ScreenSize | ConfigChanges.Locale | ConfigChanges.LayoutDirection)
        ]
    public class MainActivity : global::Xamarin.Forms.Platform.Android.FormsAppCompatActivity
    {
        protected override async void OnCreate(Bundle bundle)
        {
            TabLayoutResource = Resource.Layout.Tabbar;
            ToolbarResource = Resource.Layout.Toolbar;

            base.OnCreate(bundle);

            Xamarin.Essentials.Platform.Init(this, bundle);
            Rg.Plugins.Popup.Popup.Init(this, bundle);

            global::Xamarin.Forms.Forms.Init(this, bundle);

            FFImageLoading.Forms.Platform.CachedImageRenderer.Init(enableFastRenderer: true);

            Window.DecorView.LayoutDirection = LayoutDirection.Rtl;

            string type = Intent.GetStringExtra("SomeType");

            LoadApplication(new App(type));
        }
    }

我怎样才能解决这个问题 ?

标签: c#xamarin.formssplash-screen

解决方案


感谢@LeonLu-MSFT,我在 style.xml 中添加了这段代码,而 MainActivity 和 Spalsh Screen 没有任何变化

<item name="android:windowIsTranslucent">true</item>

我没有 Mac 和 ios 设备在 ios 中进行测试


推荐阅读