Flash screen page refers to the page that will automatically jump to the main page when the APP starts

Simply implementing a splash screen page is very simple.

Functions of the flash screen interface:

1. Display the logo, slogan and logo of the software

2. As an advertising platform, gain profits

3. Load the data needed for the next page (other Activity or global)

4. Check for updates

Results show

First, the directory structure

SplashActivity

package com.hxh.splashactivitydemo; import android.content.Intent; import android.os.Bundle; import android.support.v7.app.AppCompatActivity; import android.view.Window; import android.view.animation.AlphaAnimation; import android.view.animation.Animation; import android.widget.RelativeLayout; public class SplashActivity extends AppCompatActivity { @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); / / set has no title bar enclosing requestWindowFeature (Window. FEATURE_NO_TITLE);setContentView(R.layout.activity_splash); RelativeLayout layoutSplash=(RelativeLayout) findViewById(R.id.activity_splash); AlphaAnimation AlphaAnimation = new AlphaAnimation (1.0 0.1 f, f); alphaAnimation.setDuration(1000); / / set the flash time 1000 milliseconds (1 second) layoutSplash. StartAnimation (alphaAnimation); / / set the Animation to monitor alphaAnimation. SetAnimationListener (new Animation.AnimationListener() {@override public void onAnimationStart(Animation Animation) { OnAnimationEnd (Animation Animation) {/ / page jump Intent Intent = new Intent (SplashActivity. This, MainActivity. Class); startActivity(intent); } @Override public void onAnimationRepeat(Animation animation) { } }); }}Copy the code

MainActivityThe main interface

package com.hxh.splashactivitydemo; import android.os.Bundle; import android.support.annotation.Nullable; import android.support.v7.app.AppCompatActivity; import android.view.Window; /** * Created by HuXiaoHui on 2017/10/9. */ public class MainActivity extends AppCompatActivity { @Override protected void onCreate(@Nullable Bundle savedInstanceState) { super.onCreate(savedInstanceState); / / remove the title bar. This requestWindowFeature (Window. FEATURE_NO_TITLE);setContentView(R.layout.activity_main); }}Copy the code

activity_splash.xmlfile

<? xml version="1.0" encoding="utf-8"? > <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:id="@+id/activity_splash"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="@drawable/splash_background"
    tools:context="com.hxh.splashactivitydemo.SplashActivity">

    <TextView
        android:id="@+id/text"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_centerHorizontal="true"
        android:layout_marginTop="150dp"
        android:text="SplashDemo"
        android:textSize="50dp"
        android:textColor="#fff" />
</RelativeLayout>
Copy the code

activity_main.xml

<? xml version="1.0" encoding="utf-8"? > <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="vertical" android:layout_width="match_parent"
    android:layout_height="match_parent">
    <TextView
        android:id="@+id/text"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_centerHorizontal="true"
        android:layout_marginTop="100dp"
        android:text="Welcome to the main screen."
        android:textSize="30dp"
        android:textColor="#f00" />
</RelativeLayout>
Copy the code

The final change is neededAndroidManifest.xml

<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/AppTheme">
        <activity android:name=".SplashActivity">
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />
                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
        <activity android:name=".MainActivity" >
        </activity>
    </application>
Copy the code

First register the newly added SplashActivity in androidmanifest.xml. Then place the content under SplashActivity. This means that the SplashActivity content starts first. Then jump to MainActivity

The last

If you see this and you think it’s good, give it a thumbs up? If you think there is something worth improving, please leave a message. Will inquire seriously, correct inadequacy. thank you

I hope you can forward share and follow me, I will update the technical dry goods in the future, thank you for your support!

Forward + like + attention, the first time to get the latest knowledge

The road to being an Android architect is a long one.