英文:
Icon background color in Android 12 Splash Screen does not work
问题
在我的Android项目中,我使用Splash Screen API来为我的应用添加启动画面。我在清单中应用于应用程序的主题如下:
<style name="Launcher" parent="Theme.SplashScreen">
<item name="windowSplashScreenBackground">@color/background</item>
<item name="windowSplashScreenAnimatedIcon">@drawable/ic_launcher_foreground</item>
<item name="windowSplashScreenIconBackgroundColor">@color/orange</item>
<item name="postSplashScreenTheme">@style/AppTheme</item>
</style>
windowSplashScreenIconBackgroundColor
中的 @color/orange
应该在图标周围添加一个圆形背景。然而,背景没有被添加,只有一个图标和一个背景。
我将相应的主题添加到我的应用程序,如下所示:
<application
android:name=".App"
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name_label"
android:theme="@style/Launcher">
我尝试将启动画面的 windowSplashScreenBackground
更改为 orange
,它可以正常工作,所以问题不是我的主题被某种方式忽略了。
英文:
In my Android project I use Splash Screen API to add splash screen to my app. My theme that I apply to application in Manifest looks like this:
<style name="Launcher" parent="Theme.SplashScreen">
<item name="windowSplashScreenBackground">@color/background</item>
<item name="windowSplashScreenAnimatedIcon">@drawable/ic_launcher_foreground</item>
<item name="windowSplashScreenIconBackgroundColor">@color/orange</item>
<item name="postSplashScreenTheme">@style/AppTheme</item>
</style>
@color/orange
in windowSplashScreenIconBackgroundColor
should add circle shaped backround around icon. However, background is not added, there is just an icon and a background.
I add corresponding theme to my app as following:
<application
android:name=".App"
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name_label"
android:theme="@style/Launcher">
I tried to change splash screen windowSplashScreenBackground
to orange
and it worked, so the problem is not that my theme is ignore somehow.
答案1
得分: 2
如果你想覆盖windowSplashScreenIconBackgroundColor
,你需要扩展Theme.SplashScreen.IconBackground
主题,而不是Theme.SplashScreen
。类似于以下内容:
<style name="Launcher" parent="Theme.SplashScreen.IconBackground">
<item name="windowSplashScreenBackground">@color/background</item>
<item name="windowSplashScreenAnimatedIcon">@drawable/ic_launcher_foreground</item>
<item name="windowSplashScreenIconBackgroundColor">@color/orange</item>
<item name="postSplashScreenTheme">@style/AppTheme</item>
</style>
英文:
If you want to override windowSplashScreenIconBackgroundColor
, you have to extend Theme.SplashScreen.IconBackground
theme, not the Theme.SplashScreen
. Something like this:
<style name="Launcher" parent="Theme.SplashScreen.IconBackground">
<item name="windowSplashScreenBackground">@color/background</item>
<item name="windowSplashScreenAnimatedIcon">@drawable/ic_launcher_foreground</item>
<item name="windowSplashScreenIconBackgroundColor">@color/orange</item>
<item name="postSplashScreenTheme">@style/AppTheme</item>
</style>
答案2
得分: 0
如在闪屏界面 API中所示,请确保在项目名称前加上 android:
。
例如,将以下内容替换为:
<item name="windowSplashScreenBackground">@color/background</item>
改为:
<item name="android:windowSplashScreenBackground">@color/background</item>
这是您的当前代码:
<?xml version="1.0" encoding="utf-8"?>
<resources>
<!-- 闪屏界面 API: https://developer.android.com/develop/ui/views/launch/splash-screen#set-theme-->
<style name="Theme.MyApp" parent="@android:style/Theme.Material.NoActionBar">
<!-- 用特定的单一颜色填充背景-->
<item name="android:windowSplashScreenBackground">@color/dark</item>
<!-- 闪屏界面图标背后的背景 TODO 这不起作用 -->
<item name="android:windowSplashScreenIconBackgroundColor">@color/dark</item>
</style>
</resources>
英文:
As shown on the Splash Screen Api, Make sure you prepend the item name with android:
For example, replace:
<item name="windowSplashScreenBackground">@color/background</item>
with:
<item name="android:windowSplashScreenBackground">@color/background</item>
This is what I have:
<?xml version="1.0" encoding="utf-8"?>
<resources>
<!--Splash Screen api: https://developer.android.com/develop/ui/views/launch/splash-screen#set-theme-->
<style name="Theme.MyApp" parent="@android:style/Theme.Material.NoActionBar">
<!--fill the background with a specific single color-->
<item name="android:windowSplashScreenBackground">@color/dark</item>
<!--background behind the splash screen icon TODO this is not working -->
<item name="android:windowSplashScreenIconBackgroundColor">@color/dark</item>
</style>
</resources>
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论