8

I am trying to implement a splash screen.

I have followed the splash screen API approach implemented the implementation 'androidx.core:core-splashscreen:1.0.0-alpha02'

splash.xml

<style name="Theme.App.Start" parent="Theme.SplashScreen">
  <item name="windowSplashScreenBackground">#FFF</item>
  <item name="windowSplashScreenAnimatedIcon">@drawable/ic_baseline_baby_changing_station_24</item>
  <item name="postSplashScreenTheme">@style/Theme.SplashScreenApi</item>
</style>

splash.xml (for dark mode)

<style name="Theme.App.Start" parent="Theme.SplashScreen">
   <item name="windowSplashScreenBackground">#3A3A3A</item>
   <item name="windowSplashScreenAnimatedIcon">@drawable/ic_baseline_baby_changing_station_24</item>
   <item name="postSplashScreenTheme">@style/Theme.SplashScreenApi</item>
</style>

Manifest.xml

<application
        android:allowBackup="true"
        android:icon="@mipmap/ic_launcher"
        android:label="@string/app_name"
        android:roundIcon="@mipmap/ic_launcher_round"
        android:supportsRtl="true"
        android:theme="@style/Theme.App.Start">
        <activity
            android:name=".MainActivity"
            android:exported="true"
            android:theme="@style/Theme.App.Start">
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />

                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
</application>

MainActivity.kt

class MainActivity : AppCompatActivity() {
    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)

        installSplashScreen()

        setContentView(R.layout.activity_main)
    }
}

Still show the black icon in dark mode
splash screen dark mode

And perfectly work in light mode
splash screen light mode

Device Name: Xiaomi Redmi Note 7 Pro,
Android Version: Android 10 (SDK 29)

Nimantha
  • 6,405
  • 6
  • 28
  • 69
Raju
  • 81
  • 5

3 Answers3

3

Basically, I am getting splash as background color and launcher icon

I also face the same issue just follow my step

First of all, create values-v31(add same Theam and style file in this values-v31 folder) and values-night-v31 (add same Theam and style file in this values-night-v31 folder).

Don't use

   <style name="Theme.MySplash" parent="Theme.SplashScreen">
    <item name="windowSplashScreenBackground">@color/black</item>
    <item name="android:windowBackground">@drawable/your_logo</item>
    <item name="postSplashScreenTheme">@style/Theme.AppTheme</item>
</style>

use this one

 <style name="Theme.MySplash" parent="Theme.SplashScreen.Common">
    <item name="windowSplashScreenBackground">@color/black</item>
    <item name="android:windowBackground">@drawable/your_logo</item>
    <item name="postSplashScreenTheme">@style/Theme.AppTheme</item>
</style>
0

Change this:

<item name="postSplashScreenTheme">@style/Theme.SplashScreenApi</item>

to this:

<item name="postSplashScreenTheme">@style/AppTheme</item>

(where AppTheme is your main theme name)

Also, there's no need to apply Splash theme in both activity and application. So I would suggest you to change this in application tag :

android:theme="@style/Theme.App.Start"

to this:

android:theme="@style/AppTheme"
Nimantha
  • 6,405
  • 6
  • 28
  • 69
Sujal Kumar
  • 1,054
  • 10
  • 23
  • Actually `Theme.SplashScreenApi` is my main theme. And I change the application tag theme but not working. Show the same issue. – Raju Jan 14 '22 at 11:43
  • Have you tried using normal drawables instead of vector one? – Sujal Kumar Jan 14 '22 at 11:51
  • Yes but same as before – Raju Jan 14 '22 at 17:02
  • 1
    What if I want to set the postSplashScreenTheme at runtime? For "installSplashScreen", it says I can use "setTheme", but it doesn't say when and where, and if I should remove installSplashScreen: https://developer.android.com/reference/kotlin/androidx/core/splashscreen/SplashScreen.Companion#(android.app.Activity).installSplashScreen() "Alternatively, if a SplashScreen instance is not required, the theme can manually be set using Activity.setTheme." – android developer Jan 03 '23 at 01:08
0

Update library version to "androidx.core:core-splashscreen:1.0.0-beta02". It works fine