如果您想在一个初始屏幕中显示 2 张图像,请按照 @pinedax 的回答。但是,如果您想要 2 个完全不同的启动画面,那么这是一个单独的问题。您提供的 2 个屏幕截图适用于 2 个主题 - 浅色和深色。从 Android 10(API 级别 29)开始,谷歌已经发布了智能手机的黑暗模式。你可以阅读更多关于它here
因此,您需要拥有 2 个独立的初始屏幕 xml,并让系统根据手机的首选主题加载它们。
在 Resources/drawable 文件夹中,您可以创建 2 个文件:
splash_screen.xml:
<layer-list xmlns:android="http://schemas.android.com/apk/res/android" android:opacity="opaque">
<item android:drawable="@android:color/white"/>
<item
android:width="215dp"
android:height="105dp"
android:gravity="center">
<bitmap
android:src="@drawable/your_dark_icon_here"
android:gravity="fill"/>
</item>
splash_screen_night.xml
<layer-list xmlns:android="http://schemas.android.com/apk/res/android" android:opacity="opaque">
<item android:drawable="@android:color/black"/>
<item
android:width="215dp"
android:height="105dp"
android:gravity="center">
<bitmap
android:src="@drawable/your_light_icon_here"
android:gravity="fill"/>
</item>
</layer-list>
看看颜色和图片 - 第一个 xml 带有 white 背景和 dark 标志,第二个 xml 是深色模式的 - 浅色标志的strong>黑色背景。
之后,您需要在资源中创建一个新文件夹 - values-night。
在那里,您将拥有另外一个styles.xml 文件。现在您将拥有 2 个 styles.xml 文件 - 一个位于 Resources/values 中,一个位于 Resources/values-night
注意:注意大小写,因为这些文件夹和文件区分大小写!
在 Resources/values/styles.xml 中,您可以像这样设置启动主题:
<style name="LaunchTheme" parent="MainTheme">
<item name="android:windowBackground">@drawable/splash_screen</item>
</style>
在 Resources/values-night/styles.xml 中,您可以像这样设置启动主题:
@drawable/splash_screen_night
最后要做的就是在我们的Activity中设置闪屏。
[Activity(Label = "DarkModeSplashScreen", Icon = "@mipmap/icon", Theme = "@style/LaunchTheme", LaunchMode = LaunchMode.SingleTop, MainLauncher = true, ConfigurationChanges = ConfigChanges.ScreenSize | ConfigChanges.Orientation)]
有关详细步骤以及如何在 iOS 上实现它,您可以遵循这个很棒的教程:Xamarin: Creating a Dark Mode Splash Screen