我使用样式作为我的启动活动的主题,也是MainLauncher。这是我的闪屏画面:
<?xml version="1.0" encoding="utf-8" ?> <layer-list
xmlns:android="http://schemas.android.com/apk/res/android"> <item
android:id="@+id/itemSplashScreenBackgroundColor">
<shape android:shape="rectangle">
<solid android:color="@color/colorAppOrangeTheme" />
</shape> </item> <item>
<bitmap
android:src="@drawable/LogoSplashScreen"
android:tileMode="disabled"
android:gravity="center" /> </item> </layer-list>
这是我的style.xml文件,它使用了提到的drawable:
<resources> <style name="styleAppSplashScreenTheme"
parent="android:Theme.DeviceDefault.NoActionBar">
<item name="android:scaleType">center</item>
<item name="android:windowBackground">@drawable/XMLFileSplashScreen</item>
<item name="android:windowDisablePreview">false</item>
<item name="android:windowFullscreen">true</item>
<item name="android:windowNoTitle">true</item> </style> </resources>
如您所见,要快速启动我的应用(用户在点击应用图标后快速查看应用互动),我将windowDisablePreview的值视为false。
现在我通过Activity OnCreate方法中的以下编码更改启动画面的背景颜色:
LayerDrawable layerDrawable = (LayerDrawable)ContextCompat.GetDrawable(this, Resource.Drawable.XMLFileSplashScreen);
GradientDrawable gradientDrawable = (GradientDrawable)layerDrawable.FindDrawableByLayerId(Resource.Id.itemSplashScreenBackgroundColor);
if (stringAppThemeName == "Orange")
{
gradientDrawable.SetColor(ContextCompat.GetColor(this, Resource.Color.colorAppOrangeTheme));
}
else if (stringAppThemeName == "Blue")
{
gradientDrawable.SetColor(ContextCompat.GetColor(this, Resource.Color.colorAppBlueTheme));
}
base.OnCreate(bundleSavedInstanceState);
问题在于,当我重新启动应用程序时,首先使用默认颜色(@ color / colorAppOrangeTheme)加载样式片刻,然后更改为所需的颜色!
我看到的几个解决方案就像将windowDisablePreview设置为true但我不想取消预览窗口,我想在预览窗口中更改启动画面背景颜色的颜色。
请建议适用的解决方案。感谢。