我想在使用prism.autofac.forms nuget包的xamarin.forms应用程序中创建一个初始屏幕。基本上,我想为每个平台创建相同的启动屏幕。目前,我的Android应用程序是这样的
[Activity(Label = "MyApp", Theme = "@style/MyTheme", MainLauncher = true, ConfigurationChanges = ConfigChanges.ScreenSize | ConfigChanges.Orientation)]
public class MainActivity : FormsAppCompatActivity
{
protected override void OnCreate(Bundle bundle)
{
ToolbarResource = Resource.Layout.Toolbar;
TabLayoutResource = Resource.Layout.Tabbar;
base.OnCreate(bundle);
Forms.Init(this, bundle);
LoadApplication(new Application(new DroidInitializer()));
}
}
,应用程序如下所示:
[XamlCompilation(XamlCompilationOptions.Compile)]
public partial class Application : PrismApplication
{
public Application(IPlatformInitializer initializer) : base(initializer)
{
NavigationService.NavigateHomeAsync();
}
protected override void RegisterTypes(IContainerRegistry containerRegistry)
{
containerRegistry.RegisterForNavigation<NavigationPage>("Navigation");
containerRegistry.RegisterForNavigation<MainPage>("Index");
containerRegistry.RegisterForNavigation<HomePage>();
}
protected override void OnInitialized()
{
InitializeComponent();
}
}
我应该在哪里实现并显示启动屏幕?完成所有注册后,我想进入NavigateHome。
答案 0 :(得分:1)
启动屏幕应在平台项目中实现。
对于iOS,推荐的解决方案是为其使用情节提要https://docs.microsoft.com/en-us/xamarin/ios/app-fundamentals/images-icons/launch-screens?tabs=vsmac 对于Android设备,我用于创建初始屏幕https://docs.microsoft.com/en-us/xamarin/android/user-interface/splash-screen
的主题您可以使它们看起来相同,但是必须在每个平台上都这样做。