在平板电脑 lenovo tab m10 Android 12 上打开应用程序时,应用程序显示白色启动画面,但如果我从 Playmarket 打开,它是正常的启动画面,这只是此表的特定问题,在其他设备上都正常工作
styles.xml 灯
<?xml version="1.0" encoding="UTF-8"?>
<resources>
<style name="MyTheme" parent="MyTheme.Base">
<item name="android:windowBackground">@drawable/splashscreen</item>
</style>
<style name="MyTheme.Base" parent="Theme.AppCompat.Light.DarkActionBar">
<item name="windowNoTitle">true</item>
<item name="windowActionBar">false</item>
<item name="colorPrimary">#00adef</item>
<item name="colorPrimaryDark">#00adef</item>
<item name="colorAccent">#00adef</item>
<item name="windowActionModeOverlay">true</item>
<item name="android:datePickerDialogTheme">@style/AppCompatDialogStyle</item>
<item name="drawerArrowStyle">@style/DrawerArrowStyle</item>
<item name="android:navigationBarColor">#00adef</item>
<item name="android:windowSplashScreenIconBackgroundColor">#ffffff</item>
</style>
<style name="AppCompatDialogStyle" parent="Theme.AppCompat.Light.Dialog">
<item name="colorAccent">#FF4081</item>
</style>
<style name="DrawerArrowStyle" parent="@style/Widget.AppCompat.DrawerArrowToggle">
<item name="spinBars">true</item>
<item name="color">#ffffff</item>
</style>
<style name="MyTheme.Splash" parent="MyTheme">
<item name="android:windowSplashScreenAnimatedIcon">@drawable/lock_icon</item>
<item name="android:windowSplashScreenBrandingImage">@drawable/brand_icon</item>
<item name="android:windowSplashScreenIconBackgroundColor">@color/white</item>
<item name="android:windowSplashScreenBackground">@color/white</item>
<item name="android:windowNoTitle">true</item>
<item name="android:windowFullscreen">true</item>
<item name="android:backgroundDimEnabled">true</item>
<item name="android:navigationBarColor">#00FFFFFF</item>
</style>
</resources>
styles.xml 深色
<?xml version="1.0" encoding="UTF-8"?>
<resources>
<style name="MyTheme" parent="MyTheme.Base">
<item name="android:windowBackground">@drawable/splashscreen</item>
</style>
<style name="MyTheme.Base" parent="Theme.AppCompat.Light.DarkActionBar">
<item name="windowNoTitle">true</item>
<item name="windowActionBar">false</item>
<item name="colorPrimary">#00adef</item>
<item name="colorPrimaryDark">#00adef</item>
<item name="colorAccent">#00adef</item>
<item name="windowActionModeOverlay">true</item>
<item name="android:datePickerDialogTheme">@style/AppCompatDialogStyle</item>
<item name="drawerArrowStyle">@style/DrawerArrowStyle</item>
<item name="android:navigationBarColor">#00adef</item>
<item name="android:windowSplashScreenIconBackgroundColor">@color/black</item>
</style>
<style name="AppCompatDialogStyle" parent="Theme.AppCompat.Light.Dialog">
<item name="colorAccent">#FF4081</item>
</style>
<style name="DrawerArrowStyle" parent="@style/Widget.AppCompat.DrawerArrowToggle">
<item name="spinBars">true</item>
<item name="color">#ffffff</item>
</style>
<style name="MyTheme.Splash" parent="MyTheme">
<item name="android:windowSplashScreenAnimatedIcon">@drawable/lock_icon_dark</item>
<item name="android:windowSplashScreenBrandingImage">@drawable/brand_icon_dark</item>
<item name="android:windowSplashScreenIconBackgroundColor">@color/black</item>
<item name="android:windowSplashScreenBackground">@color/black</item>
<item name="android:windowNoTitle">true</item>
<item name="android:windowFullscreen">true</item>
<item name="android:backgroundDimEnabled">true</item>
<item name="android:navigationBarColor">#00FFFFFF</item>
</style>
</resources>
splashscreen.xml
<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
<item>
<shape android:shape="rectangle">
<solid android:color="#f2f2f2"/>
</shape>
</item>
<item>
<bitmap
android:gravity="center"
android:src="@drawable/splash_image"/>
</item>
<item android:bottom="85dp">
<bitmap
android:gravity="bottom|center_horizontal"
android:src="@drawable/brand_icon"/>
</item>
</layer-list>
SplashScreen.cs
[Activity(MainLauncher = true,
NoHistory = true,
Theme = "@style/MyTheme.Splash",
Exported = true)]
public class SplashScreen : AppCompatActivity
{
protected override void OnCreate(Bundle savedInstanceState)
{
base.OnCreate(savedInstanceState);
var intent = new Intent(this, typeof(MainActivity));
if (Intent?.Extras != null)
{
intent.PutExtras(Intent.Extras);
}
StartActivity(intent);
}
}
我厌倦了添加
<item name="android:windowBackground">@drawable/splashscreen</item>
但它并没有真正起作用
另外,如果我要改变颜色
<item name="android:windowSplashScreenBackground">@color/white</item>
它也会变色
这不是在 Android 12 设备上制作闪屏的方法。旧的 Layer.list 技术将不再起作用。
请参阅 https://github.com/gmck/XamarinBasicSplashScreen 以展示如何正确执行此操作。