Search
 
SCRIPT & CODE EXAMPLE
 

JAVA

How do I make a splash screen?

//MainActivity.java

import androidx.appcompat.app.AppCompatActivity;
import android.os.Bundle;

public class MainActivity extends AppCompatActivity {

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

//splashscreen.java

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.os.Handler;

public class splashscreen extends Activity {
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.splashscreen);

        //Splash Screen duration
        int secondsDelayed = 1;
        new Handler().postDelayed(new Runnable() {
            public void run() {
                startActivity(new Intent(splashscreen.this, MainActivity.class));
                finish();
            }
        }, secondsDelayed * 3000);
    }
}

//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"
    tools:context=".MainActivity">

    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="Hello World!"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintLeft_toLeftOf="parent"
        app:layout_constraintRight_toRightOf="parent"
        app:layout_constraintTop_toTopOf="parent" />

</androidx.constraintlayout.widget.ConstraintLayout>

//splashscreen.xml

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="vertical" android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="@drawable/splashlogo"

    />
      
Source: https://github.com/Lunox-Code/SplashScreen
Comment

PREVIOUS NEXT
Code Example
Java :: sort array based on string length java 
Java :: java xmx example 
Java :: object to string in java 
Java :: get imei programmatically android 
Java :: como calcular a raiz quadrada em java 
Java :: reading csv file in java 
Java :: How to do press enter to continue in java 
Java :: java foreach 
Java :: boolean print condition java 
Java :: open gallery android 
Java :: Java List Sort Using sort() method 
Java :: insert data into list java 
Java :: h2 database spring boot 
Java :: dijkstra java 
Java :: java separate the numbers from string 
Java :: counting nodes in binary search tree 
Java :: java.lang.NoClassDefFoundError: javax/xml/bind/JAXBException 
Java :: android java xml combo box 
Java :: string to hexstring In java 
Java :: android studio change menu title 
Java :: Get the last Friday of a month in Java 
Java :: simple login password and username java 
Java :: replace substring at index java 
Java :: java list distinct by object attribute 
Java :: java 8 map foreach 
Java :: how to check if string is double or not in java 
Java :: java remove space at the end of string 
Java :: declaration of double array in java 
Java :: find first element of list java 
Java :: compare two times in java 
ADD CONTENT
Topic
Content
Source link
Name
3+4 =