Latest News

Splash Screen (Kotlin) - Android Studio

      DESCRIPTION      

In this tutorial i'll show you how to create a splash screen for your android app using android studio. We need at least two activities one is splash screen and second is some other activity that will display after splash screen.

      VIDEO      



      SOURCE CODE      

Step 1: Create a new project OR Open your project

Step 2: Create New Activity File>New>Activity>EmptyActivity

Step 3: Place an image in res>drawable folder

Step 4: Open manifest and add

android:theme="@style/Theme.AppCompat.Light.NoActionBar"
in <activity android:name=".SplashActivity" ...>

Step 5: Code

AndroidMenifest.xml
<?xml version="1.0" encoding="utf-8"?><manifest xmlns:android="http://schemas.android.com/apk/res/android"package="com.blogspot.atifsoftwares.splashscreenapp"><applicationandroid:allowBackup="true"android:icon="@mipmap/ic_launcher"android:label="@string/app_name"android:roundIcon="@mipmap/ic_launcher_round"android:supportsRtl="true"android:theme="@style/AppTheme"><activityandroid:name=".SplashActivity"android:theme="@style/Theme.AppCompat.Light.NoActionBar"><intent-filter><action android:name="android.intent.action.MAIN" /><category android:name="android.intent.category.LAUNCHER" /></intent-filter></activity><activity android:name=".MainActivity"></activity></application></manifest>

activity_splash.xml
<?xml version="1.0" encoding="utf-8"?><LinearLayout 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:orientation="vertical"android:gravity="center"android:background="@color/colorPrimary"tools:context=".SplashActivity"><ImageViewandroid:src="@drawable/logo"android:layout_width="250dp"android:layout_height="250dp" /><TextViewandroid:layout_width="wrap_content"android:layout_height="wrap_content"android:text="Loading..."android:textColor="#fff"android:textSize="30sp"android:textStyle="bold" /></LinearLayout>

SplashActivity.kt
package com.blogspot.atifsoftwares.splashscreenappimport android.content.Intentimport android.support.v7.app.AppCompatActivityimport android.os.Bundleimport android.os.Handlerimport android.view.Windowimport android.view.WindowManagerclass SplashActivity : AppCompatActivity() {override fun onCreate(savedInstanceState: Bundle?) {super.onCreate(savedInstanceState)//hiding title kafe of this activitywindow.requestFeature(Window.FEATURE_NO_TITLE)//making this activity full screenwindow.setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN , WindowManager.LayoutParams.FLAG_FULLSCREEN)setContentView(R.layout.activity_splash)//4second splash timeHandler().postDelayed({//start main activitystartActivity(Intent(this@SplashActivity , MainActivity::class.java))//finish this activityfinish()} ,4000)}}

activity_main.xml
<?xml version="1.0" encoding="utf-8"?><LinearLayout 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:orientation="vertical"android:gravity="center"tools:context=".MainActivity"><TextViewandroid:text="Welcome"android:textSize="30sp"android:layout_width="wrap_content"android:layout_height="wrap_content" /></LinearLayout>

MainActivity.kt
package com.blogspot.atifsoftwares.splashscreenappimport android.support.v7.app.AppCompatActivityimport android.os.Bundleclass MainActivity : AppCompatActivity() {override fun onCreate(savedInstanceState: Bundle?) {super.onCreate(savedInstanceState)setContentView(R.layout.activity_main)}}

Step 6: Run Project

Output
Splash Screen (Kotlin) - Android Studio


0 Response to "Splash Screen (Kotlin) - Android Studio"