I want to have a splash screen in my app that also supports version below android 12. I found this article Jetpack Compose: Splash Screen API. I follow all the steps. But the icon is filling the entire screen as below.
Using android:width,height did not solve the problem (Attribute width is only used in API level 23 and higher (current min is 21)). I’m testing the app in a physical device (Samsung s4 which run android 5.1, cause virtual device is slow).
Other solutions i found was to modify the image size, this caused the image to be noisy.
layer-list
<?xml version="1.0" encoding="utf-8"?>
<!-- res/drawable/splash_background.xml -->
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
<!-- Background color -->
<item android:drawable="@color/black" />
<!-- Background image or drawable -->
<item >
<bitmap
android:src="@drawable/spotify"
android:gravity="center"/>
</item>
</layer-list>
theme file
<?xml version="1.0" encoding="utf-8"?>
<resources>
<style name="Theme.AudioApp" parent="android:Theme.Material.Light.NoActionBar" />
<style name="Theme.SplashScreen" parent="android:Theme.Material.Light.NoActionBar">
<item name="android:statusBarColor">@color/black</item>
<item name="android:windowBackground">@drawable/splash_background</item>
</style>
</resources>
the SplashActivity
@SuppressLint("CustomSplashScreen")
class SplashActivity: ComponentActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
lifecycleScope.launchWhenCreated {
delay(3000)
val intent = Intent(this@SplashActivity, MainActivity::class.java)
startActivity(intent)
finish()
}
}
}
This is the output of code, the logo here has a high quality, just because I transferred it from devices.
The spotify logo is 512x512px, when i try to make it smaller it’s get distorted using an online image resizer. Here is the exact result it gets blurred and noisy.