Create the background with logo for Splash Screen insplash_screen.xml
under res/drawable
:
<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android" android:opacity="opaque">
<item android:drawable="@color/splash_screen_bg_color" />
<item android:drawable="@drawable/splash_logo" />
</layer-list>
Create Style for Splash Screen in res/values/styles.xml
:
<!-- Splash screen theme -->
<style name="SplashScreenTheme" parent="Theme.AppCompat.NoActionBar">
<item name="android:windowBackground">@color/splash_screen_bg_color</item>
</style>
**Notes: **If I want to modify styles of Status Bar or Bottom Nav, modify attributes in res/values/style.xml
file (Ref: Attributes in styles.xml):
<item name="android:windowFullscreen">true</item>
<item name="android:windowTranslucentNavigation">true</item>
Set style as theme for SplashScreenActivity
in AndroidManifest.xml
:
<!-- Splash Screen Activity -->
<activity android:name=".activity.SplashScreenActivity"
android:theme="@style/SplashScreenTheme">
<intent-filter>
<action android:name="android.intent.action.MAIN"/>
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
AndroidManifest.xml
**Notes: **Make sure comment this line because we want the SplashScreenThemeActivity
be the LAUNCHER
. Otherwise, it will load MainActivity
automatically.
Create a SlashScreenActivity
:
public class SplashScreenActivity extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
Intent intent = new Intent(SplashScreenActivity.this, MainActivity.class);
startActivity(intent);
finish();
}
}
**Notes: **As we are loading the splash screen them from manifest. So there is no need to setContentView() with any xml layout.
#android #splash-screen