我在我的应用程序中添加了一个启动画面
<item name="android:windowBackground">@drawable/splashScreen</item>
到我申请的MainTheme
。
应用程序启动时,启动画面会正确显示,但在应用程序的所有页面中仍保留为背景。
我该如何避免这种行为?
Here一个视频,以更好地显示行为。
谢谢!
您需要至少有两个主题。一个用于启动画面,另一个用于应用程序的其余部分(您还可以为特定页面设置其他主题)。
在我的情况下,我有闪屏的“splashscreen”和应用程序的其余部分的“AppTheme”。
将splash主题定义为:
<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(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);
}