Splash Screen Tutorial With Example In Android Studio
Splash Screen is most commonly the first startup screen which appears when App is opened. In other words, it is a simple constant screen for a fixed amount of time which is used to display the company logo, name, advertising content etc.
activity_splash.xml
step 1:
<?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:background="@color/healthy"
android:layout_height="match_parent"
android:gravity="center"
android:orientation="vertical"
tools:context=".SplashActivity">
<androidx.cardview.widget.CardView
android:layout_width="200dp"
android:layout_height="200dp"
app:cardCornerRadius="100dp">
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:scaleType="fitXY"
android:src="@drawable/healthy"/>
</androidx.cardview.widget.CardView>
<TextView
android:layout_marginTop="10dp"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="SR Application Ltd."
android:textSize="30dp"
android:textStyle="bold"
android:textColor="@color/white"/>
</LinearLayout>
SplashActivity.java
step 2:
package com.sandhya.androidallproject2023;
import androidx.appcompat.app.AppCompatActivity;
import android.content.Intent;
import android.os.Bundle;
import android.os.Handler;
public class SplashActivity extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_splash);
getSupportActionBar().hide();
new Handler().postDelayed(new Runnable() {
@Override
public void run() {
// Intent intent = new Intent(getApplicationContext(),MainActivity.class);
Intent intent = new Intent(SplashActivity.this,MainActivity.class);
startActivity(intent);
finish();
}
},5000);
}
}
Output:-
Generating Download Link...
إرسال تعليق