javaandroidandroid-studiosplash-screen

How to make Android Splash Screen Fullscreen


This is my code. I am following a tutorial on Youtube. When I use android:theme="@android:style/Theme.Light.NoTitleBar.Fullscreen" the screen does not show the splash screen and shows a blank screen instead. My code is as the following.

<activity
   android:name="com.nowate.customerapp.activity.SplashActivity"
   android:screenOrientation="portrait"
   android:theme="@style/AppTheme.NoActionBar" >
   <intent-filter>
      <action android:name="android.intent.action.MAIN" />

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

Solution

  • This is the proper way to add a splash screen to your app. It doesn't take any fixed time to display it because it is showing while the app really loads.

    1. Declare a new theme in styles.xml:
     <style name="SplashTheme" parent="Theme.AppCompat.Light.NoActionBar">
            <item name="android:windowBackground">@drawable/splash_screen</item>
            <item name="android:windowFullscreen">true</item>
            <item name="android:windowTranslucentNavigation">true</item>
            <item name="android:windowDrawsSystemBarBackgrounds">true</item>
     </style>
    
    1. Set the theme in AndroidManifest to your launcher activity (don't create a new activity just for a splash screen):
    <activity
       android:name="com.nowate.customerapp.activity.MainActivity"
       android:screenOrientation="portrait"
        android:theme="@style/SplashTheme" >
       <intent-filter>
          <action android:name="android.intent.action.MAIN" />
    
          <category android:name="android.intent.category.LAUNCHER" />
       </intent-filter>
    </activity>
    
    1. In your MainActivity in the onCreate() method set the original theme befor setting the layout:
    setTheme(R.style.AppTheme);
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
    
    1. Example of splash screen drawable ("ic_loading" is a vector):
    <?xml version="1.0" encoding="utf-8"?>
    <layer-list xmlns:android="http://schemas.android.com/apk/res/android">
        <item>
            <shape
                android:shape="rectangle">
                <solid android:color="@color/black" />
            </shape>
        </item>
        <item
            android:gravity="center"
            android:drawable="@drawable/ic_loading"/>
    </layer-list>