gpt4 book ai didi

layout - Xamarin : Splash screen using a Layout

转载 作者:行者123 更新时间:2023-12-01 17:22:51 28 4
gpt4 key购买 nike

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

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

谢谢

最佳答案

您可以做的是创建一个代表您的启动屏幕的事件。例如: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);
}
}

关于layout - Xamarin : Splash screen using a Layout,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27987195/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com