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 运行时图标不会显示。
在此处添加我的评论作为答案以获得更好的可见性。
我确实弄清楚了如何让它显示出来。我正在按照本教程设置一个基础项目来重现问题,我注意到作者在底部附近放置的注释提到仅运行应用程序不会显示完整的启动屏幕。您必须杀死它并从启动器打开应用程序。一旦我这样做了,我就能看到我的启动画面。很烦人,但至少我现在有办法测试它。我确实也为此记录了错误报告,但我现在有一个解决办法。感谢大家的回答/评论!
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"行后,它开始工作。
由于某种原因,当应用程序通过 android studio 启动时,它不显示图标。终止应用程序并从菜单启动应用程序。然后就会出现图标。如果您不使用 Splash API,则情况如此:https://developer.android.com/develop/ui/views/launch/splash-screen/migrate
| 归档时间: |
|
| 查看次数: |
39333 次 |
| 最近记录: |