Monday, January 28, 2019
Add a splash screen, is a great way to open you app, especially if its graphics heavy like a game.
first create a xml file under the drawable folder (drawable/splash_screen.xml)
You can add a new theme under your res/values/styles.xml file
NOTE: splash screen will only work if you use the parent theme.AppCompat and your MainActivity class needs to extend the AppCompatActivity class. see below
Now all you have to do is change some lines in you manifests/AdroidManifest.xml file
As you can see, we are telling our app to use the SplashScreenTheme theme when it LAUNCHER. And the SplashScreenTheme reference drable/splash_screen as its windowBackground.
I hope this article has been helpful.
first create a xml file under the drawable folder (drawable/splash_screen.xml)
<?xml version="1.0" encoding="utf-8"?><layer-list xmlns:android="http://schemas.android.com/apk/res/android" android:layout_height="match_parent" android:layout_width="match_parent"> <item android:drawable="@color/colorPrimary"/> <!-- Set the Background Image--> <item android:gravity="center" android:width="500dp" android:height="500dp"> <bitmap android:gravity="fill_horizontal|fill_vertical" android:src="@drawable/splash_screen_image"/> </item> </layer-list>
You can add a new theme under your res/values/styles.xml file
<style name="SplashScreenTheme" parent="Theme.AppCompat.Light.DarkActionBar"> <item name ="android:windowBackground"> @drawable/splash_screen</item> </style>
NOTE: splash screen will only work if you use the parent theme.AppCompat and your MainActivity class needs to extend the AppCompatActivity class. see below
public class MainActivity extends AppCompatActivity {
Now all you have to do is change some lines in you manifests/AdroidManifest.xml file
<activity android:name=".SplashActivity" android:theme="@style/SplashScreenTheme"> <intent-filter> <action android:name="android.intent.action.MAIN" /> <category android:name="android.intent.category.LAUNCHER" /> </intent-filter> </activity> <activity android:name=".MainActivity" />
As you can see, we are telling our app to use the SplashScreenTheme theme when it LAUNCHER. And the SplashScreenTheme reference drable/splash_screen as its windowBackground.
I hope this article has been helpful.