0

On running my app on a device, it shows a blank screen for sometime and then it starts.

Blank screen image

Splash Screen Code :

 new Handler().postDelayed(new Runnable()
        {
            @Override
            public void run()
            {
                Intent splash = new Intent(SplashActivity.this, ListActivity.class);
                startActivity(splash);
                finish();
            }
        }, 1000);
    }
Praveen
  • 3,186
  • 2
  • 8
  • 23

1 Answers1

1

Your app is having a white screen at the start because the app waits to get the current theme of the app and then loads your splash screen.

For setting splash screen so the app opens instantly with it, you have to create a new theme inside styles.xml

<style name="SplashScreen" parent="Theme.MaterialComponents.Light.NoActionBar">
    <item name="android:windowBackground">@drawable/splash</item>
    <item name="android:statusBarColor">@color/spalshStatusBar</item>
</style>

Create your splash.xml drawable with your app's icon in the center

<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
    <item android:drawable="@color/splashBackground" />
    <item
        android:drawable="@drawable/ic_app_icon"
        android:gravity="center" />
</layer-list>

Set this theme as default in your manifest application tag

<application
      ..
      android:theme="@style/SplashScreen"
      ..
      ..>

Now once your app's theme loading completes, change your app theme accordingly.

Praveen
  • 3,186
  • 2
  • 8
  • 23