How to make a splash screen

This is the first post in a few days. I'm a student programmer who is still studying how the app works, but I'll do my best!

How to make a splash screen

I will keep up with you. This screen is quite important when creating an app. It's annoying to come out every time, but I think it's the best way to actually recognize the app name. Smartnews, Gunosy, Twitter, etc ... You will be able to remember the name by displaying this each time you open it. So let's do it right away! !!

Step 1 Edit styles.xml

image.png Add a new style to res / values / styles.xml. This time, let's call it Splash Theme. First select styles.xml.

styles.xml


<resources>

    <!-- Base application theme. -->
    <style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
        <!-- Customize your theme here. -->
        <item name="colorPrimary">#EA5E5D</item>
        <item name="colorPrimaryDark">#EA5E5D</item>
        <item name="colorAccent">#EA5E5D</item>
    </style>
<!--Please copy and paste from here.-->
    <style name="AppTheme.NoActionBar">
        <item name="windowActionBar">false</item>
        <item name="windowNoTitle">true</item>
    </style>
    <style name="AppTheme.AppBarOverlay" parent="ThemeOverlay.AppCompat.Dark.ActionBar" />

    <style name="AppTheme.PopupOverlay" parent="ThemeOverlay.AppCompat.Light" />

    <style name="SplashTheme" parent="AppTheme">
        <item name="android:windowBackground">@mipmap/imageview</item>
    </style>
</resources>

Step 2 Edit the Manifest file

Add the style you set earlier.

AndroidManifest.xml


<application
        android:allowBackup="true"
        android:icon="@mipmap/i_topics_icon"
        android:label="@string/app_name"
        android:roundIcon="@mipmap/i_topics_icon"
        android:supportsRtl="true"
        android:theme="@style/AppTheme">
<!--Add below from here.-->
        <activity android:name=".MainActivity"
            android:theme="@style/SplashTheme">
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />
                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
<activity android:name=".MainActivity"
            android:theme="@style/SplashTheme">
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />
                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>

Be sure to add here. Since the splash screen is displayed only once, please prepare a theme separately from the application theme. I had a lot of trouble not doing that lol

Step 3 Edit Activity

MainActivity.java


package android.wings.websarva.com.splash;

import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;

public class MainActivity extends AppCompatActivity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
//Add from here
        try {
            Thread.sleep(2000);

        } catch (InterruptedException e) {
            e.printStackTrace();
        }
        setTheme(R.style.AppTheme);
//So far
        setContentView(R.layout.activity_main);

    }
}

You can now add it. You can pause the thread for the specified time by using sleep provided by the Thread class. This time I want to stop for 2 seconds, so set thread.sleep (2000).

image.png image.png

I think the screen will switch like this.

Articles that I used as a reference https://qiita.com/yamikoo@github/items/c82ea335968709a9d32a It was very easy to understand. Thank you very much.

Recommended Posts

How to make a splash screen
[Swift5] How to create a splash screen
How to make a Java container
How to make a JDBC driver
How to make a Jenkins plugin
How to make a Maven project
How to make a Java array
How to make a Java calendar Summary
How to make a Discord bot (Java)
How to make shaded-jar
How to make a lightweight JRE for distribution
How to make a follow function in Rails
Java --How to make JTable
How to leave a comment
[Rails] How to make seed
How to insert a video
How to create a method
How to make a factory with a model with polymorphic association
How to make JavaScript work on a specific page
How to make a cache without thinking too much
How to make a mod for Slay the Spire
How to add columns to a table
Try to make a simple callback
[Rails] How to prevent screen transition
Learning Ruby with AtCoder 13 How to make a two-dimensional array
How to write a ternary operator
[Swift] How to send a notification
Try to make a peepable iterator
[Android] How to make Dialog Fragment
How to make a hinadan for a Spring Boot project using SPRING INITIALIZR
[Rails 6] How to create a dynamic form input screen using cocoon
How to automatically operate a screen created in Java on Windows
How to identify the path that is easy to make a mistake
How to make a groundbreaking diamond using Java for statement wwww
[Xcode] How to add a README.md file
How to execute a contract using web3j
How to sort a List using Comparator
A memorandum on how to use Eclipse
How to redo a deployment on Heroku
[Basic] How to write a Dockerfile Self-learning ②
How to add a new hash / array
[Introduction to Java] How to write a Java program
How to create a Maven repository for 2020
How to print a Java Word document
How to pass the value to another screen
[Swift5] How to implement standby screen using'PKHUD'
[rails] How to create a partial template
How to make asynchronous pagenations using Kaminari
How to publish a library in jCenter
[SpringBoot] How to write a controller test
How to make an app with a plugin mechanism [C # and Java]
Rails: How to write a rake task nicely
How to create a database for H2 Database anywhere
[Rails] How to write when making a subquery
How to deploy a container on AWS Lambda
[Rails] How to create a graph using lazy_high_charts
[Android] How to convert a character string to resourceId
Make a margin to the left of the TextField
How to get a heapdump from a Docker container
How to make rbenv recognize OpenSSL on WSL
How to display a web page in Java