Xamarin Forms - Android 启动画面也显示在主应用程序中

Xamarin Forms - Android Splashscreen are shown also in main application

我在我的应用程序中添加了启动画面添加

<item name="android:windowBackground">@drawable/splashScreen</item>

我申请的 MainTheme

启动画面在应用程序启动时正确显示,但在应用程序的所有页面中仍作为背景。

如何避免这种行为?

Here 一个更好地展示行为的视频。

谢谢!

您至少需要有两个主题。一个用于启动画面,另一个用于应用程序的其余部分(您也可以为特定页面设置其他主题)。

在我的例子中,我有 "splashscreen" 用于初始屏幕,"AppTheme" 用于应用程序的其余部分。

将启动主题定义为:

<style name="splashscreen" parent="Theme.AppCompat.Light.NoActionBar">
    <item name="android:windowBackground">@drawable/Zenon_Welcome_Screen</item>
    <item name="android:windowNoTitle">true</item>
    <item name="android:windowIsTranslucent">false</item>
    <item name="android:windowIsFloating">false</item>
    <item name="android:backgroundDimEnabled">true</item>
    </style>

AppTheme 为:

<style name="AppTheme" parent="AppTheme.Base">
  </style>
  <!-- App theme applied no matter what API -->
  <style name="AppTheme.Base" parent="Theme.AppCompat.Light.DarkActionBar">
    <!--If you are using revision 22.1 please use just windowNoTitle. Without android:-->
    <item name="windowNoTitle">true</item>
    <!--We will be using the toolbar so no need to show ActionBar-->
    <item name="windowActionBar">false</item>
    <!-- Set theme colors from http://www.google.com/design/spec/style/color.html#color-color-palette -->
    <!-- colorPrimary is used for the default action bar background -->
    <item name="colorPrimary">#c62828</item>
    <!-- colorPrimaryDark is used for the status bar -->
    <item name="colorPrimaryDark">#8e0000</item>
    <!-- colorAccent is used as the default value for colorControlActivated
         which is used to tint widgets -->
    <item name="colorAccent">#8e0000</item>
    <item name="windowActionModeOverlay">true</item>
    <item name="android:datePickerDialogTheme">@style/AppCompatDialogStyle</item>
  </style>

现在在你的主要 activity :

[Activity(Label = "AppName", Icon = "@drawable/icon", Theme = "@style/splashscreen", MainLauncher = true,
              ConfigurationChanges = ConfigChanges.ScreenSize | ConfigChanges.Orientation, ScreenOrientation = ScreenOrientation.Portrait,
        LaunchMode = LaunchMode.SingleTask)]
    public class MainActivity : FormsAppCompatActivity

现在在 onCreate 方法中你需要切换主题如下:

        /// <summary>
        ///    On create.
        /// </summary>
        /// <param name="bundle">Bundle.</param>
        protected override void OnCreate(Bundle bundle)
        {
            base.Window.RequestFeature(WindowFeatures.ActionBar);

            // Name of the MainActivity theme we want to use for the app.
            // Or we can use global::Android.Resource.Style.ThemeHoloLight / Theme Name.
            base.SetTheme(Resource.Style.AppTheme);

            base.OnCreate(bundle);
        }