使用 Xamarin 布局创建 SplashScreen

Create SplashScreen with layout Xamarin

我正在尝试在 Xamarin Studio 中创建启动画面。

我做了以下事情:

由于某种原因,它不起作用,我希望你能在这里帮助我:

SplashScreen.cs(启动画面activity)

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading;

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

namespace EvoApp
{
    [Activity (MainLauncher = true, NoHistory = true, Theme = "@style/Theme.Splash")]           
    public class SplashScreen : Activity
    {
        protected override void OnCreate (Bundle bundle)
        {
            base.OnCreate (bundle);

            this.SetContentView (Resource.Layout.Splash);

            ImageView image = FindViewById<ImageView> (Resource.Id.evolticLogo);
            image.SetImageResource (Resource.Drawable.Splash);

            Thread.Sleep (2000);
            StartActivity (typeof(MainActivity));
        }
    }
}

styles.xml

<?xml version="1.0" encoding="UTF-8" ?>
<resources>
  <style name="Theme.Splash" parent="android:Theme">
    <item name="android:windowNoTitle">true</item>
  </style>
</resources>

所以结果是一个空白的 SplashActivity....

提前致谢!

屏幕是空白的,因为通过调用 Thread.Sleep 然后在 OnCreateView 中调用 StartActivity,您首先暂停了 UI 线程(这不会导致任何显示)并且然后使用 StartActivity 立即退出 activity。

要解决此问题,请将 Thread.Sleep()StartActivity() 转移到后台线程中:

protected override void OnCreate (Bundle bundle)
{
    base.OnCreate (bundle);

    this.SetContentView (Resource.Layout.Splash);

    ImageView image = FindViewById<ImageView> (Resource.Id.evolticLogo);
    image.SetImageResource (Resource.Drawable.Splash);

    System.Threading.Tasks.Task.Run( () => {
        Thread.Sleep (2000);
        StartActivity (typeof(MainActivity));
    });
}