Search code examples
androidxmlsplash-screen

Adding a progress indicator to Google's new Splashscreen pattern


Having gone through this blog post Splash Screens the Right Way , i discovered Google's new approach to creating splashscreens.

But my problem with this new method is adding a progress bar/indicator to the splashscreen.

I found several solutions but they are all custom xml layouts instead of Drawables

I also tried creating a progress dialog in my Background_splash.xml which is inside my drawable folder but i got an error that it is not allowed.

My app starts from the splash-screen to App intro activity then to the Main activity.

Is there any way to add a progress indicator/bar to this type of splashscreen?

Below are my codes created using the Splash Screens the Right Way Tutorial

Background_splash.xml

<?xml version="1.0" encoding="utf-8"?>

<item
    android:drawable="@color/grey"/>

<item>
    <bitmap
        android:gravity="center"
        android:src="@mipmap/ic_launcher"/>

</item>

AndroidManifest.xml

    <activity
        android:name="com.domain.app.appintro.SplashActivity"
        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.AppCompat.NoActionBar">
    <item name="android:windowBackground">@drawable/background_splash</item>
</style>

Solution

  • The answer is you cannot! If you want to show the splash screen before the app loads, via the theme, it will have to be a static image.
    If you want to show a progress bar AFTER the app loads, for example if you need to download data, then you can add a progress bar to splash activity, which will be shown AFTER the static image and app finished loading.
    If you do not need to wait after app loads, then you are just wasting user time by adding another wait period, and making for a lousy app.
    All of this can be understood from the comments and replies from the article you linked.