在Android 12闪屏界面中,图标背景颜色无法正常工作。

huangapple go评论65阅读模式
英文:

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:

&lt;style name=&quot;Launcher&quot; parent=&quot;Theme.SplashScreen&quot;&gt;
    &lt;item name=&quot;windowSplashScreenBackground&quot;&gt;@color/background&lt;/item&gt;
    &lt;item name=&quot;windowSplashScreenAnimatedIcon&quot;&gt;@drawable/ic_launcher_foreground&lt;/item&gt;
    &lt;item name=&quot;windowSplashScreenIconBackgroundColor&quot;&gt;@color/orange&lt;/item&gt;
    &lt;item name=&quot;postSplashScreenTheme&quot;&gt;@style/AppTheme&lt;/item&gt;
&lt;/style&gt;

@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:

&lt;application
    android:name=&quot;.App&quot;
    android:allowBackup=&quot;true&quot;
    android:icon=&quot;@mipmap/ic_launcher&quot;
    android:label=&quot;@string/app_name_label&quot;
    android:theme=&quot;@style/Launcher&quot;&gt;

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:

&lt;style name=&quot;Launcher&quot; parent=&quot;Theme.SplashScreen.IconBackground&quot;&gt;
    &lt;item name=&quot;windowSplashScreenBackground&quot;&gt;@color/background&lt;/item&gt;
    &lt;item name=&quot;windowSplashScreenAnimatedIcon&quot;&gt;@drawable/ic_launcher_foreground&lt;/item&gt;
    &lt;item name=&quot;windowSplashScreenIconBackgroundColor&quot;&gt;@color/orange&lt;/item&gt;
    &lt;item name=&quot;postSplashScreenTheme&quot;&gt;@style/AppTheme&lt;/item&gt;
&lt;/style&gt;

答案2

得分: 0

如在闪屏界面 API中所示,请确保在项目名称前加上 android:

例如,将以下内容替换为:

&lt;item name=&quot;windowSplashScreenBackground&quot;&gt;@color/background&lt;/item&gt;

改为:

&lt;item name=&quot;android:windowSplashScreenBackground&quot;&gt;@color/background&lt;/item&gt;

这是您的当前代码:

&lt;?xml version=&quot;1.0&quot; encoding=&quot;utf-8&quot;?&gt;
&lt;resources&gt;
    &lt;!-- 闪屏界面 API: https://developer.android.com/develop/ui/views/launch/splash-screen#set-theme--&gt;
    &lt;style name=&quot;Theme.MyApp&quot; parent=&quot;@android:style/Theme.Material.NoActionBar&quot;&gt;
        &lt;!-- 用特定的单一颜色填充背景--&gt;
        &lt;item name=&quot;android:windowSplashScreenBackground&quot;&gt;@color/dark&lt;/item&gt;
        &lt;!-- 闪屏界面图标背后的背景  TODO 这不起作用 --&gt;
        &lt;item name=&quot;android:windowSplashScreenIconBackgroundColor&quot;&gt;@color/dark&lt;/item&gt;
    &lt;/style&gt;
&lt;/resources&gt;
英文:

As shown on the Splash Screen Api, Make sure you prepend the item name with android:

For example, replace:

&lt;item name=&quot;windowSplashScreenBackground&quot;&gt;@color/background&lt;/item&gt;

with:

&lt;item name=&quot;android:windowSplashScreenBackground&quot;&gt;@color/background&lt;/item&gt;

This is what I have:

&lt;?xml version=&quot;1.0&quot; encoding=&quot;utf-8&quot;?&gt;
&lt;resources&gt;
    &lt;!--Splash Screen api: https://developer.android.com/develop/ui/views/launch/splash-screen#set-theme--&gt;
    &lt;style name=&quot;Theme.MyApp&quot; parent=&quot;@android:style/Theme.Material.NoActionBar&quot;&gt;
        &lt;!--fill the background with a specific single color--&gt;
        &lt;item name=&quot;android:windowSplashScreenBackground&quot;&gt;@color/dark&lt;/item&gt;
        &lt;!--background behind the splash screen icon  TODO this is not working --&gt;
        &lt;item name=&quot;android:windowSplashScreenIconBackgroundColor&quot;&gt;@color/dark&lt;/item&gt;
    &lt;/style&gt;
&lt;/resources&gt;

huangapple
  • 本文由 发表于 2023年2月8日 20:52:50
  • 转载请务必保留本文链接:https://go.coder-hub.com/75386086.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定