Android 12 启动画面图标不显示

Jos*_*tes 72 android splash-screen android-12 android-api-31

我发现我正在启动的新应用程序出现奇怪的问题。我正在利用新的 Android 12 启动画面 API 来创建启动画面,并按照Google 提供的指南进行操作。我在项目中包含了 core-splashscreen,以提供与旧版本 Android 操作系统的兼容性。当我运行该应用程序时,我会在 API 30 等旧操作系统版本上看到预期的启动屏幕,但当我在 API 31 上运行它时,我提供的启动屏幕图标不会显示。显示了我指定的背景颜色,但根本不存在图标。我已经尝试使用可绘制资源和 mipmap 进行此操作,但没有任何效果。我很困惑,因为我找到的每个教程都显示了我所遵循的相同步骤以及他们工作启动屏幕的屏幕截图,但我没有任何运气。

对于上下文,这里是我对 v31 的启动屏幕样式定义:

<style name="Theme.Splash" parent="Theme.SplashScreen">
    <item name="android:windowSplashScreenBackground">@color/orange_7A</item>
    <item name="android:windowSplashScreenAnimatedIcon">@drawable/splash_foreground</item>
    <item name="postSplashScreenTheme">@style/Theme.App</item>
</style>
Run Code Online (Sandbox Code Playgroud)

我对所有其他操作系统版本都有相同的样式,除了我使用“windowSplashScreenAnimatedIcon”而不是“android:windowSplashScreenAnimatedIcon”。我尝试过 v31 在项目名称前面有或没有“android:”,但都不起作用。这是我的 MainActivity.kt:

class MainActivity : AppCompatActivity() {

override fun onCreate(savedInstanceState: Bundle?) {
    super.onCreate(savedInstanceState)

    installSplashScreen()
    
    setContent {
        MyVeevaTheme {
            Login()
        }
    }
}
Run Code Online (Sandbox Code Playgroud)

我还在 AndroidManifest.xml 中将“android:theme”属性设置为我的启动样式。我知道正在应用启动样式,因为它尊重背景颜色,但由于某种原因它没有显示图标,即使图标在旧操作系统版本中显示良好。预先感谢您可以提供的任何帮助。

Jos*_*tes 129

TL;DR 终止应用程序并从启动器运行,从 Android Studio 运行时图标不会显示。

在此处添加我的评论作为答案以获得更好的可见性。

我确实弄清楚了如何让它显示出来。我正在按照本教程设置一个基础项目来重现问题,我注意到作者在底部附近放置的注释提到仅运行应用程序不会显示完整的启动屏幕。您必须杀死它并从启动器打开应用程序。一旦我这样做了,我就能看到我的启动画面。很烦人,但至少我现在有办法测试它。我确实也为此记录了错误报告,但我现在有一个解决办法。感谢大家的回答/评论!

  • 这个问题快把我逼疯了。我遵循了有关如何迁移的 Google 指南以及有关 SplashScreen API 的其他文档。但在我的 Pixel 上,我使用 Nova Launcher 作为桌面,当使用 Nova Launcher 从快捷方式或抽屉启动应用程序时,您永远不会在启动屏幕上看到图标/图像。使用 Android Studio 启动时仍然如此。当我使用 Pixel Launcher 启动应用程序时,我只在启动屏幕上看到了图标/图像。做得太差了。 (11认同)
  • 天啊,安卓。总是能给人惊喜。看起来它仍然有 bug(嗯,lib 是测试版,所以毫不奇怪 - 但它已经强制执行 api 级别 31)感谢 Joseph 的解决方法,这已经节省了我很多时间!但是我无法访问错误报告,链接是否正确?@Gimberg 提到的其他启动器的问题也非常烦人。 (8认同)
  • 我发现了其他人记录的另一份报告,谷歌似乎将此标记为预期行为...参考链接:https://issuetracker.google.com/199776339 (2认同)

Muh*_*lib 12

人们根据文档 installSplashScreen() 应该在 super.onCreate() 之前调用


Vad*_*aen 10

当您使用 AndroidX SplashScreen 库时,就像您所做的 ( Theme.SplashScreen) 一样,您需要使用windowSplashScreen*不带android:前缀的属性。

android:前缀用于调用平台属性,但在这种情况下,您使用的是库而不是平台,因此不需要前缀:

res/values/themes.xml

<style name="Theme.Splash" parent="Theme.SplashScreen">
    <item name="windowSplashScreenBackground">@color/orange_7A</item>
    <item name="windowSplashScreenAnimatedIcon">@drawable/splash_foreground</item>
    <item name="postSplashScreenTheme">@style/Theme.App</item>
</style>
Run Code Online (Sandbox Code Playgroud)


小智 10

就我而言,缺少启动屏幕的问题是默认活动主题的安装:

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools">

    <application
        android:name=".App"
        android:theme="@style/Theme.Tracker.StartSplashScreen"
        android:icon="@mipmap/ic_launcher"
        android:label="@string/app_name"
        android:supportsRtl="true"
        android:allowBackup="true"
        android:dataExtractionRules="@xml/data_extraction_rules"
        android:fullBackupContent="@xml/backup_rules"
        tools:targetApi="tiramisu">
        <activity
            android:name=".MainActivity"
            android:exported="true"
            android:theme="@style/Theme.Tracker">                 <-------
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />
                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
    </application>

</manifest>
Run Code Online (Sandbox Code Playgroud)

当我删除android:theme="@style/Theme.Tracker"行后,它开始工作。


Iva*_*lov 6

由于某种原因,当应用程序通过 android studio 启动时,它不显示图标。终止应用程序并从菜单启动应用程序。然后就会出现图标。如果您不使用 Splash API,则情况如此:https://developer.android.com/develop/ui/views/launch/splash-screen/migrate