与布局Xamari创建闪屏 [英] Create SplashScreen with layout Xamari
问题描述
我试着去创造Xamari Studio中的启动画面。
Im trying to create a splashscreen in Xamari Studio.
我做了以下内容:
- 创建了布局,在splashimage。
- 创建的主题(styles.xml),所以标题栏被隐藏。
- 创建了设置内容查看,然后一个活动让线程睡眠。
出于某种原因,没有工作,我希望你能帮助我在这里:
For some reason it did not work and I hoped you could help me out here:
SplashScreen.cs(闪屏活动)
SplashScreen.cs (SplashScreen 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
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 ....
So the result of this is a blank SplashActivity....
在此先感谢!
推荐答案
屏幕是空白的,因为通过调用 Thread.sleep代码
然后 StartActivity
在 OnCreateView
,你先暂停UI线程(这将导致没有显示),然后由立即退出活动使用 StartActivity
。
The screen is blank because by calling Thread.Sleep
then StartActivity
in OnCreateView
, you are first pausing the UI thread (which will cause nothing to display) and are then exiting the activity immediately by using StartActivity
.
要解决这个问题,移 Thread.sleep代码()
和 StartActivity()
进入后台线程:
To fix this, shift Thread.Sleep()
and StartActivity()
into a background thread:
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));
});
}
这篇关于与布局Xamari创建闪屏的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!