因此,我try 添加一个图像作为闪屏,我已经添加了mipmap中的某些密度文件,作为plash.png.
因此,我想为Android 12及以上以及以下Android 12处理闪屏实现,因为在Android 12中,他们引入了新的SplashScreen API.所以我得同时处理两件事.
因此,我try 通过如下实现来处理问题:
下面是res/value/styles. xml的代码:
<!-- For devices below Android 12 -->
<style name="SplashTheme" parent="@android:style/Theme.Light.NoTitleBar">
<item name="android:windowBackground">@mipmap/splash</item>
</style>
<!-- For devices Android 12 or higher -->
<style name="SplashTheme_S" parent="@android:style/Theme.Light.NoTitleBar">
<item name="windowSplashScreenBackground">@mipmap/splash</item>
</style>
AndroidManifest. xml的代码:
<activity
android:name=".MainActivity"
android:exported="true"
android:launchMode="singleTop"
android:configChanges="orientation|keyboardHidden|keyboard|screenSize|smallestScreenSize|locale|layoutDirection|fontScale|screenLayout|density|uiMode"
android:hardwareAccelerated="true"
android:windowSoftInputMode="adjustResize">
<!-- Specifies an Android theme to apply to this Activity as soon as
the Android process has started. This theme is visible to the user
while the Flutter UI initializes. After that, this theme continues
to determine the Window background behind the Flutter UI. -->
<meta-data
android:name="io.flutter.embedding.android.NormalTheme"
android:resource="@style/NormalTheme"
/>
<intent-filter>
<action android:name="android.intent.action.MAIN"/>
<category android:name="android.intent.category.LAUNCHER"/>
</intent-filter>
</activity>
MainActivity.kt:
package com.myorg.mynotes
import android.os.Build
import android.os.Bundle
import android.util.Log
import io.flutter.embedding.android.FlutterActivity
class MainActivity: FlutterActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
Log.d("MainActivity", "SDK_INT: ${Build.VERSION.SDK_INT}")
// Dynamically set splash screen theme based on Android version
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.S) {
Log.d("MainActivity", "Using SplashTheme_S for Android 12 or higher")
setTheme(R.style.SplashTheme_S)
Log.d("MainActivity", "After setTheme function")
} else{
Log.d("MainActivity", "Using SplashTheme for Android versions below 12")
setTheme(R.style.SplashTheme)
Log.d("MainActivity", "After setTheme function")
}
super.onCreate(savedInstanceState)
}
}
我希望上面的代码能够动态处理闪屏,但它并没有这样做.我做错了什么?