Xamarin:使用布局启动画面

时间:2015-01-16 15:22:58

标签: layout xamarin screen splash

我正在尝试为我的Android应用程序创建启动画面,如此链接http://developer.xamarin.com/guides/android/user_interface/creating_a_splash_screen/

所示

不幸的是,此链接仅显示如何使用drawable制作闪屏。但我需要做的是使用布局创建一个启动画面,以便我可以轻松自定义它的外观并使其与不同的屏幕尺寸兼容。

由于

1 个答案:

答案 0 :(得分:8)

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

要阻止用户导航回到splash活动,只需将NoHistory = true属性添加到ActivityAttribute(就在活动类decleration上方)。

参见示例:     

    [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);
        }
    }
相关问题