Android development--simple implementation of the startup page of Android applications

Android startup page effect display

When you usually open the app on your phone, a 3-second advertisement will pop up before you enter the app. Today we will simply implement the function of the guide page.

1. First, create a new activity page and name it: SplashActivity

Add the content of the startup page in activity_splash.xml, I added a picture here (the picture is placed under the drawable file), the code is as follows:

<?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/zhz"
    tools:context=".SplashActivity">
<ImageView
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:src="@drawable/zhz"></ImageView>
</androidx.constraintlayout.widget.ConstraintLayout>

In the java file, hide the status bar and title bar of the startup page, and set the display time of the startup page to 3 seconds.

SplashActivity.java code is as follows:

public class SplashActivity extends AppCompatActivity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        //隐藏状态栏
        getWindow().addFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN);
        //隐藏标题栏
        getSupportActionBar().hide();
        setContentView(R.layout.activity_splash);
        //创建子线程
        Thread mThread=new Thread(){
            @Override
            public void run() {
                super.run();
                try {
                    sleep(3000);//使程序休眠3秒
                    Intent intent=new Intent(getApplicationContext(),MainActivity.class);
                    startActivity(intent);
                    finish();
                }catch (Exception e){
                    e.printStackTrace();
                }
            }
        };
        mThread.start();//启动线程
    }
}

2. In the AndroidManifest.xml file, set the startup page to .SplashActivity, the code is as follows:

<activity android:name=".StartActivity">
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />

                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
</activity>

3. I have changed the application icon to my own picture here. You can change it according to your own needs (you can not change it), the code is as follows:

 At this point, you have completed all the steps, run it and try it out!

The result of the operation is as follows:

Android startup page effect display

Of course, you can also add more styles to the startup page according to your own needs, come on!

Guess you like

Origin blog.csdn.net/Waterme10n/article/details/124198398