Reputation: 1
I am trying to create splash screen and set it as a Splash theme its not picking up the background color and even the branded icon and showing default screen with android rounded logo with grey background.
theme.xml
<resources xmlns:tools="http://schemas.android.com/tools">
<!-- Base application theme. -->
<style name="Theme.BaseMVVM" parent="Theme.MaterialComponents.DayNight.NoActionBar">
<!-- Primary brand color. -->
<item name="colorPrimary">@color/purple_500</item>
<item name="colorPrimaryVariant">@color/purple_700</item>
<item name="colorOnPrimary">@color/white</item>
<!-- Secondary brand color. -->
<item name="colorSecondary">@color/teal_200</item>
<item name="colorSecondaryVariant">@color/teal_700</item>
<item name="colorOnSecondary">@color/black</item>
<!-- Status bar color. -->
<item name="android:statusBarColor" tools:targetApi="l">?attr/colorPrimaryVariant</item>
</style>
</resources>
Splash.xml
<?xml version="1.0" encoding="utf-8"?>
<resources xmlns:tools="http://schemas.android.com/tools">
<style name="Theme.BaseMVVM.Initial" parent="Theme.SplashScreen">
<item name="android:windowSplashScreenBackground" tools:targetApi="s">@color/teal_200</item>
<item name="android:windowSplashScreenAnimatedIcon" tools:targetApi="s">@drawable/ic_baseline_article_24</item>
<item name="android:windowSplashScreenBrandingImage" tools:targetApi="s">@drawable/ic_baseline_article_24</item>
<item name="postSplashScreenTheme">@style/Theme.BaseMVVM</item>
</style>
</resources>
Menifest:
<activity
android:theme="@style/Theme.BaseMVVM.Initial"
android:name=".SplashActivity"
android:exported="true">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
SplashActivity:
class SplashActivity : AppCompatActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
val splashScreen = installSplashScreen()
super.onCreate(savedInstanceState)
splashScreen.setKeepOnScreenCondition { true }
lifecycleScope.launchWhenCreated {
delay(2000)
gotoHomeActivity()
}
}
Upvotes: 0
Views: 102
Reputation: 302
I was able to reproduce the problem by by adding the android namespace in the the Splash.xml items which makes it target android 12 and above only.
<item name="android:windowSplashScreenBackground" tools:targetApi="s">@color/teal_200</item>
<item name="android:windowSplashScreenAnimatedIcon" tools:targetApi="s">@drawable/ic_baseline_article_24</item>
<item name="android:windowSplashScreenBrandingImage" tools:targetApi="s">@drawable/ic_baseline_article_24</item>
When the android attribute is used the splash screen wont be available to lower levels of android . To use the Compatibility API,omit the android attribute for the items and use it like this:
<item name="windowSplashScreenBackground" >@color/teal_200</item>
<item name="windowSplashScreenAnimatedIcon" >@drawable/ic_baseline_article_24</item>
<item name="windowSplashScreenBrandingImage" >@drawable/ic_baseline_article_24</item>
The Android Documentation has a guide too
Upvotes: 1