android kotlin splash screen example
Hi, developer in this Kotlin tutorial we are sharing an example for the Android Kotlin splash screen. we create a new android project with select kotlin then select an empty activity with the name splash screen. finish it. After the let’s make a design for splash screen open your XML file and make a beautiful splash screen android studio.
Beautiful splash screen android studio
Table of Contents
Let’s Start making UI for Your Splash Screen follow below code for UI Design you can customize according to your requirement. Open your Splash activity XML file and used this code.
activity_splesh.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="fill_parent" android:layout_height="fill_parent" android:background="@drawable/screen_back" android:orientation="vertical" tools:context=".MainActivity"> <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="fill_parent" android:layout_height="fill_parent" android:background="@drawable/screen_back" android:orientation="vertical" tools:context=".Splash_Screen"> <LinearLayout android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_centerInParent="true" android:orientation="vertical"> <ImageView android:id="@+id/App_Icons" android:layout_width="match_parent" android:layout_height="180dp" android:layout_gravity="center" android:layout_weight="1" android:src="@drawable/codeplaylogo" app:tint="@color/white" /> </LinearLayout> <LinearLayout android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_alignParentBottom="true" android:orientation="vertical"> <ProgressBar android:id="@+id/ProgressBar" style="?android:attr/progressBarStyleHorizontal" android:layout_width="220dp" android:layout_height="wrap_content" android:layout_gravity="center" android:indeterminate="true" android:indeterminateTint="@color/white" /> <TextView android:layout_width="match_parent" android:layout_height="wrap_content" android:text="Codeplayon Learn share and Explore " android:layout_gravity="bottom" android:gravity="center" android:textColor="@color/white" android:layout_marginBottom="40dp" android:padding="10dp" android:textStyle="bold" /> </LinearLayout> </RelativeLayout> </LinearLayout>
code these code and past you splash screen XML file after that create a screen_back Drawable XML file for the splash screen background.for making a sharp for the screen.
Screen_back drawable XML file code
<?xml version="1.0" encoding="utf-8"?> <selector xmlns:android="http://schemas.android.com/apk/res/android"> <item> <shape android:shape="rectangle"> <stroke android:width="0dp" android:color="@color/white" /> <gradient android:angle="45" android:centerColor="@color/purple_500" android:centerX="0%" android:endColor="@color/white" android:startColor="@color/teal_700" ></gradient> <corners android:bottomRightRadius="0dp" android:topLeftRadius="0dp" android:bottomLeftRadius="0dp" android:topRightRadius="0dp" /> </shape> </item> </selector>
Splash_Screen Kotlin file source code.
class SplashActivity : AppCompatActivity() { private val SPLASH_TIME_OUT = 3000 private val TAG = "Splash_Screen" var progressBar: ProgressBar? = null override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) setContentView(R.layout.activity_main) progressBar = findViewById(R.id.ProgressBar) Handler().postDelayed({ val intent = Intent(this, Home_Activity::class.java) startActivity(intent) finish() }, SPLASH_TIME_OUT.toLong()) } }
after adding these code in you splash screen kotlin file you can create a new activity for redirect to splash to home_screen. And add NoActionbar then for your activity in the manifest file.
<?xml version="1.0" encoding="utf-8"?> <manifest xmlns:android="http://schemas.android.com/apk/res/android" package="com.codeplayon.kotlintutorial"> <application android:allowBackup="true" android:icon="@mipmap/ic_launcher" android:label="@string/app_name" android:roundIcon="@mipmap/ic_launcher_round" android:supportsRtl="true" android:theme="@style/Theme.CodeplayonKotlinTutorial"> <activity android:name=".Home_Activity" android:label="@string/title_activity_home_"></activity> <activity android:name=".MainActivity" android:theme="@style/Theme.AppCompat.NoActionBar"> <intent-filter> <action android:name="android.intent.action.MAIN" /> <category android:name="android.intent.category.LAUNCHER" /> </intent-filter> </activity> </application> </manifest>
run your project and see the result.