使用新的Android API创建的启动画面不显示,这是什么问题?

00jrzges  于 2024-01-04  发布在  Android
关注(0)|答案(1)|浏览(117)

我试图添加一个闪屏与新的Android API.问题是,我的应用程序上工作有一个奇怪的白色闪屏与应用程序的标志,但我不能在所有的代码中看到的地方正在引入,和自定义我想把没有出现.
这是SplashActivity的代码(该类在清单中显示为LAUNCHER,在意图中显示为MAIN

  1. override fun onCreate(savedInstanceState: Bundle?) {
  2. super.onCreate(savedInstanceState)
  3. installSplashScreen()
  4. Firebase.inAppMessaging.setMessagesSuppressed(true)
  5. initStetho()
  6. initTracker()
  7. setUpToolbar()
  8. checkDynamicLink()
  9. updateTaxonomies = true
  10. }

字符串
onResume只验证演示者类的数据。
这是申请清单

  1. <application
  2. android:name=".B4workApp"
  3. android:allowBackup="true"
  4. android:hardwareAccelerated="true"
  5. android:icon="@mipmap/ic_app_adaptive_icon"
  6. android:label="@string/app_name"
  7. android:largeHeap="true"
  8. android:roundIcon="@mipmap/ic_app_adaptive_icon_round"
  9. android:theme="@style/Theme.App.Starting">


以及启动器活动

  1. <activity
  2. android:name=".newcode.presentation.splash.SplashActivity"
  3. android:clearTaskOnLaunch="true"
  4. android:exported="true"
  5. android:largeHeap="true"
  6. android:launchMode="singleTask"
  7. android:screenOrientation="unspecified"
  8. android:theme="@style/AppThemeTransparentStatus">
  9. <intent-filter>
  10. <action android:name="android.intent.action.MAIN" />
  11. <category android:name="android.intent.category.LAUNCHER" />
  12. </intent-filter>


除了用于可浏览类别和来自后端的关联数据之外,还有其他意图过滤器标签。
最后是涉及的主题:

AppTheme

  1. <style name="AppTheme" parent="Theme.AppCompat.Light.NoActionBar">
  2. <!-- colorPrimary is used for the default action bar background -->
  3. <item name="colorPrimary">@color/transparent</item>
  4. <!-- colorPrimaryDark is used for the status bar -->
  5. <item name="colorPrimaryDark">@color/emperor</item>
  6. <!-- colorAccent is used as the default value for colorControlActivated,
  7. which is used to tint widgets -->
  8. <item name="colorAccent">@color/emperor</item>
  9. <!-- You can also set colorControlNormal, colorControlActivated
  10. colorControlHighlight, and colorSwitchThumbNormal. -->
  11. <item name="android:textColor">@color/gray</item>
  12. <item name="android:textColorPrimary">@color/gray</item>
  13. <item name="android:textColorSecondary">@color/emperor</item>
  14. <item name="android:actionMenuTextColor">@color/emperor</item>
  15. <!-- Support library compatibility -->
  16. <item name="android:actionMenuTextAppearance">@style/customActionBar</item>
  17. </style>

AppThememeEventStatus

  1. <style name="AppThemeTransparentStatus" parent="AppTheme">
  2. <!-- colorPrimary is used for the default action bar background -->
  3. <item name="colorPrimary">@color/transparent</item>
  4. <!-- colorPrimaryDark is used for the status bar -->
  5. <item name="colorPrimaryDark">@color/transparent</item>
  6. <!-- colorAccent is used as the default value for colorControlActivated,
  7. which is used to tint widgets -->
  8. <item name="colorAccent">@color/emperor</item>
  9. <item name="android:textColor">@color/gray</item>
  10. <item name="android:textColorPrimary">@color/gray</item>
  11. <item name="android:actionMenuTextColor">@color/gray</item>
  12. <!-- Support library compatibility -->
  13. <item name="android:actionMenuTextAppearance">@style/customActionBar</item>
  14. </style>

Splash主题

  1. <style name="Theme.App.Starting" parent="Theme.SplashScreen">
  2. <item name="windowSplashScreenBackground">@color/black</item>
  3. <item name="windowSplashScreenAnimatedIcon">@drawable/b4w_splash_icon_anim</item>
  4. <item name="windowSplashScreenAnimationDuration">3000</item>
  5. <item name="postSplashScreenTheme">@style/AppTheme</item>
  6. </style>


drawable是一个动画矢量drawable作为docs说,但没有任何动画,我已经尝试了简单的矢量太多,因为YouTube教程做他们和工作。
但在开始的时候,


的数据
我已经审查了应用程序的所有模块和所有风格,我不明白为什么出现白色屏幕
更新:如果需要logcat消息:

  1. 2023-12-22 09:52:52.517 900-957 SplashScreenView com.android.systemui D Build android.window.SplashScreenView{1903f10 V.E...... ......ID 0,0-0,0}
  2. Icon: view: android.widget.ImageView{401ea09 V.ED..... ......I. 0,0-0,0 #10204a7 android:id/splashscreen_icon_view} drawable: com.android.wm.shell.startingsurface.SplashscreenIconDrawableFactory$ImmobileIconDrawable@615940e size: 504
  3. Branding: view: android.view.View{b207e2f G.ED..... ......I. 0,0-0,0 #10204a6 android:id/splashscreen_branding_view} drawable: null size w: 0 h: 0


似乎没有很好地建立起来,但不知道为什么
编辑:解决了,我只需要修改我的styles.xml,现在它对apis 31和更高版本可见,使用本教程:https://medium.com/@radomir9720/android-splash-screen-easy-setup-for-both-11-version-and-lower-and-12-287ccb86f9c7

q0qdq0h2

q0qdq0h21#

尝试在super.onCreate(savedInstanceState)之前调用installSplashScreen()

  1. override fun onCreate(savedInstanceState: Bundle?) {
  2. installSplashScreen() // should be called before onCreate
  3. super.onCreate(savedInstanceState)
  4. ...
  5. }

字符串
在onCreate方法中,启动Activity,**在super.onCreate()**之前调用installSplashScreen。您还需要确保postSplashScreenTheme设置为应用的主题。或者,如果不需要SplashScreen示例,则可以将此调用替换为Activity#setTheme。

相关问题