我试图在Xamarin Studio中创建一个启动画面。
我做了以下事情:
出于某种原因,它不起作用,我希望你能在这里帮助我:
SplashScreen.cs(SplashScreen活动)
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 ....
提前致谢!
答案 0 :(得分:4)
屏幕显示为空白,因为在Thread.Sleep
中调用StartActivity
然后OnCreateView
,您首先暂停UI线程(这将导致无法显示任何内容),然后立即退出活动使用StartActivity
。
要解决此问题,请将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));
});
}