【问题标题】:App stuck on the Splash screen in Android 12 (API Level 31)应用程序卡在 Android 12(API 级别 31)的初始屏幕上
【发布时间】:2021-12-13 14:11:12
【问题描述】:

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

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>

styles.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'

StartUpActivity 代码:

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

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

【问题讨论】:

    标签: android kotlin android-api-levels android-12 android-splashscreen


    【解决方案1】:

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

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

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

    【讨论】:

    • 问题出在壁画图像加载库中。现在可以了
    猜你喜欢
    • 2017-11-05
    • 1970-01-01
    • 2017-05-08
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-12-26
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多