【问题标题】:Xamarin : Splash screen using a LayoutXamarin:使用布局的启动画面
【发布时间】:2015-01-16 15:22:57
【问题描述】:

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

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

谢谢

【问题讨论】:

  • 您不需要布局来使其与不同的屏幕尺寸兼容。如果您使用的布局意味着在用户启动应用程序和显示初始屏幕之间需要更多时间。

标签: layout xamarin screen splash-screen


【解决方案1】:

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

为了防止用户导航回启动活动,您只需将NoHistory = true 属性添加到 ActivityAttribute(就在活动类声明的上方)。

参见示例:

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

【讨论】:

    猜你喜欢
    • 2020-08-02
    • 2021-11-26
    • 1970-01-01
    • 2022-01-04
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-11-26
    相关资源
    最近更新 更多