繁体   English   中英

应用卡在 Android 12(API 级别 31)的启动画面上

[英]App stuck on the Splash screen in Android 12 (API Level 31)

应用程序卡在启动画面上。 不知道为什么? 我所做的一切都与文档相同。 请看我的代码,请告诉。

Android Manifest.xml 文件代码:

   <activity
        android:name=".ui.startup.StartupActivity"
        android:exported="true"
        android:label="@string/app_name"
        android:screenOrientation="portrait"
        android:theme="@style/SplashTheme">
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />
            <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>
    </activity>

样式.xml 代码

<style name="SplashTheme" parent="Theme.SplashScreen">
    <item name="windowActionBar">false</item>
    <item name="windowNoTitle">true</item>
    <item name="windowSplashScreenAnimatedIcon">@drawable/splash</item>
</style>

app.gradle 依赖代码:

implementation 'androidx.core:core-splashscreen:1.0.0-alpha01'

启动活动代码:

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

 override fun onStart() {
    super.onStart()
    proceedNavigation()
 }

我尚未在 Android 12 中实现启动画面,但根据您的代码和某些文档,您需要添加 setConetView 并且您必须在它之前调用 installSplashScreen()。

override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
installSplashScreen()
setContenView(layout)
}

override fun onStart() {
super.onStart()
proceedNavigation()
} 

参考

根据本文档,您必须在主活动或启动器活动中调用 installSplashScreen 函数。 您必须在 setContentView 之前调用它。

override fun onCreate(savedInstanceState: Bundle?) {
    super.onCreate(savedInstanceState)
    val splashScreen = installSplashScreen()
    setContentView(R.layout.activity_main)

您还应该考虑为属性 postSplashScreenTheme 指定活动主题,以便您可以为启动画面和应用程序设置单独的主题。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM