[TOC]
The app will show white screen
or black screen
each time when you cold start the app. For UX or UI, this is not good user experenice.
For that, we will fix knid of small problem with the splash view
.
Create a drawable
view in your drawable folder, named splash_view.xml
.
<?xml version="1.0" encoding="utf-8"?>
<layer-list
xmlns:android="http://schemas.android.com/apk/res/android"
android:opacity="opaque">
<item android:drawable="?colorPrimary"/>
<item>
<bitmap
android:gravity="center"
android:src="@drawable/YOUR_PIC"/>
</item>
</layer-list>
Declare the style
to your styles file.
<style name="AppTheme.Splash">
<item name="android:windowBackground">@drawable/splash_view</item>
</style>
Create an activity
for the splash view. You can customize how long to show the splash view.
class SplashActivity: Activity() {
companion object {
private val SPLASH_DELAY_TIME: Long = 500
}
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
// Delay 0.5 second for showing the splash view.
Handler().postDelayed({
this.let {
// Transfer to your main activity after delay 0.5 second.
it.startActivity(Intent(this, MainActivity::class.java))
it.finish()
}
}, SPLASH_DELAY_TIME)
}
}
Set the splash view in your AndroidManifests.xml
.
<application
android:name="myapp.myapp"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:largeHeap="true"
android:supportsRtl="true"
android:theme="@style/AppTheme">
<!-- Your theme here!!! -->
<activity
android:name=".ui.activities.SplashActivity"
android:theme="@style/AppTheme.Splash">
<intent-filter>
<action android:name="android.intent.action.MAIN"/>
<category android:name="android.intent.category.LAUNCHER"/>
</intent-filter>
</activity>
<activity android:name="myapp.myapp.SecondActivity"></activity>
<activity android:name="myapp.myapp.ThirdActivity"></activity>
</application>