Splash Screen:- It comes first when the user opens or starts the app. It relates to the entire app. You can use your design what do you want.
Implementation of Splash Screen
# Follow these steps to set up Splash Screen.
- Create a new empty activity first.
- After creating the new activity, design your desired view in this activity’s XML file. Like below
SplashScreen.xml
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@color/windowBackground"
tools:context=".activities.SplashScreenActivity">
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical"
android:layout_centerVertical="true"
android:layout_centerHorizontal="true">
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@mipmap/ic_launcher"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="All In One"
android:padding="10dp"
android:layout_gravity="center_horizontal"
android:textColor="@color/black"/>
</LinearLayout>
</RelativeLayout>
SplashScreen.kt
3. Create a variable for storing the splash screen time, like TIME_OUT.
private var TIME_OUT:Long = 3000
4. Create a function for the load splash screen. Like loadSplashScreen(). Call Handler().postDelayed() to handle the activity. Then add your next activity to open after the splash screen. postDepayed() function will take two parameters,1st parameter for the next activity, 2nd the parameter for the splash screen's time.
private fun loadSplashScreen(){
Handler().postDelayed({
// You can declare your desire activity here to open after finishing splash screen. Like MainActivity
val intent = Intent(this,MainActivity::class.java)
startActivity(intent)
finish()
},TIME_OUT)
}
5. Now call your loadSplashScreen function in the onCreate() function to display it.
class SplashScreenActivity : AppCompatActivity() {
// After 3000 mileSeconds / 3 seconds your next activity will display.
private var TIME_OUT:Long = 3000
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_splash_screen)
loadSplashScreen()
}
}
AndroidManifest.xml
6. After completing your desire design for the splash screen, Open AndroidManifest.xml. You can see your splash screen’s activity in the AndroidManifest.xml file.
<activity android:name=".activities.SplashScreenActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
You can see the name of the splash screen in the application section above.
7. Add an intent-filter section in your splash screen’s activity, Like above
8. intent-filter will launch this activity first when a user opens or start the app.
I hope it will help
Thanks:)