Xamarin:使用布局启动画面 [英] Xamarin : Splash screen using a Layout

查看:67
本文介绍了Xamarin:使用布局启动画面的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试为我的android应用程序创建启动屏幕,如以下链接所示: http://developer.xamarin.com/guides/android/user_interface/creating_a_splash_screen/

I am trying to create splash screen for my android application, as shown in this link http://developer.xamarin.com/guides/android/user_interface/creating_a_splash_screen/

不幸的是,此链接仅显示了如何使用可绘制对象制作启动屏幕.但是我需要做的是使用布局"创建启动屏幕,以便我可以轻松自定义其外观并使其与不同的屏幕尺寸兼容.

Unfortunately this link just shows how to make a splash screen using a drawable. But what I need to do is to create a splash screen using a Layout so that I can easily customize how it looks and make it compatible with different screen sizes.

谢谢

推荐答案

您可以做的是创建一个代表您的初始屏幕的Activity.例如:SplashActivity.然后,在创建SplashActivity时,您将启动一个持续时间为3秒的计时器(例如:System.Timers.Timer).经过3秒后,您只需启动应用程序的主要活动即可.

What you can do is to create a Activity that represents your splash screen. Ex: SplashActivity. Then when your SplashActivity is created you start a timer (Ex: System.Timers.Timer) with 3 seconds duration. When those 3 seconds have passed you simply start the main activity for your app.

要防止用户导航回初始活动,您只需将NoHistory = true属性添加到ActivityAttribute中(就在活动类定义上方).

To prevent the user from navigating back to the splash activity, you simply add the NoHistory = true property to the ActivityAttribute (just above the activity class decleration).

请参阅示例:

See example:

    [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);
        }
    }

这篇关于Xamarin:使用布局启动画面的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆