我正在尝试为我的 Android 应用程序创建启动屏幕,如此链接所示http://developer.xamarin.com/guides/android/user_interface/creating_a_splash_screen/ http://developer.xamarin.com/guides/android/user_interface/creating_a_splash_screen/
不幸的是,这个链接只展示了如何使用可绘制对象制作启动屏幕。但我需要做的是使用布局创建启动屏幕,以便我可以轻松自定义它的外观并使其与不同的屏幕尺寸兼容。
Thanks
您可以做的是创建一个代表您的启动屏幕的活动。前任:SplashActivity
。然后,当您的 SplashActivity 创建后,您将启动一个计时器(例如:System.Timers.Timer
)持续时间为 3 秒。当这 3 秒过去后,您只需开始应用程序的主要活动即可。
为了防止用户导航回启动画面活动,您只需添加NoHistory = true
属性到活动属性(就在活动类声明之上)。
参见示例:
[Activity(MainLauncher = true, NoHistory = true, Label = "My splash app", Icon = "@drawable/icon")]
public class SplashActivity : Activity
{
protected override void OnCreate(Bundle bundle)
{
base.OnCreate(bundle);
SetContentView(Resource.Layout.Splash);
Timer timer = new Timer();
timer.Interval = 3000; // 3 sec.
timer.AutoReset = false; // Do not reset the timer after it's elapsed
timer.Elapsed += (object sender, ElapsedEventArgs e) =>
{
StartActivity(typeof(MainActivity));
};
timer.Start();
}
};
[Activity (Label = "Main activity")]
public class MainActivity : Activity
{
protected override void OnCreate (Bundle bundle)
{
base.OnCreate (bundle);
// Set our view from the "main" layout resource
SetContentView (Resource.Layout.Main);
}
}
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)