How to create splash screen in android studio

How to create splash screen in android studio
An easy and simple method to create a Splash screen. This video gave an easy method to create the first android screen. We create 2 activity first launch activity mean splash screen and after time over automatically redirect another mean activity 2 screens. First, we will create a simple splash screen and then set the logo and background image
Splash Screen
Splash Screen


activity_main.xml
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout 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="@drawable/bg"
    tools:context=".MainActivity">


    <ImageView
        android:id="@+id/imageview"
        android:layout_width="150dp"
        android:layout_height="150sp"
        android:src="@drawable/logo"
        app:layout_constraintBottom_toTopOf="@+id/progressBar"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintHorizontal_bias="0.498"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toTopOf="parent"
        app:layout_constraintVertical_bias="0.621" />

    <ProgressBar
        android:id="@+id/progressBar"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginBottom="36dp"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintHorizontal_bias="0.534"
        app:layout_constraintStart_toStartOf="parent"></ProgressBar>

</androidx.constraintlayout.widget.ConstraintLayout>

MainActivity.java
package com.example.splashdemo;

import androidx.appcompat.app.AppCompatActivity;

import android.content.Intent;
import android.os.Bundle;
import android.os.Handler;
import android.widget.ImageView;

public class MainActivity extends AppCompatActivity {
ImageView imageview;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate ( savedInstanceState );
        setContentView ( R.layout.activity_main );
imageview=findViewById ( R.id.imageview );
imageview.setAlpha ( 130 );//make image transparent
        new Handler (  ).postDelayed ( new Runnable () {
            @Override
            public void run() {
          startActivity ( new Intent ( MainActivity.this,Main2Activity.class ) );//after go to another activity
            }
        },5000 );//delay time
    }
}

After creating new empty activity 
activity_main2.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:gravity="center"
    tools:context=".Main2Activity">

    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="Welcome to splash screen"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toTopOf="parent"
        android:textSize="25sp"></TextView>
</LinearLayout>

Main2Activity.java
package com.example.splashdemo;

import androidx.appcompat.app.AppCompatActivity;

import android.os.Bundle;

public class Main2Activity extends AppCompatActivity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate ( savedInstanceState );
        setContentView ( R.layout.activity_main2 );
    }
}


splash screen in android studio



watch youtube 
https://youtu.be/tsWAT-7AeiA

SUBSCRIBE to download

Download Source code
إرسال تعليق (0)
أحدث أقدم