Android studio production welcome interface and Application Icon

Keywords: Android xml Java encoding

Preface

Hello, I'm Vic. Today I'll give you an overview of Android studio's production welcome interface and application icons. I hope you like it

Welcome interface and Application Icon

This project uses Android Studio 3.0.1 as a development tool

activity_splash.xml

An activity_splash.xml layout file is created. To welcome the layout of the interface, first change it to RelativeLayout layout

<?xml version="1.0" encoding="utf-8"?>
<!--Add a welcome background-->
<RelativeLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width = "match_parent"
    android:layout_height="match_parent"
    android:background="@drawable/launch_bg">
    <!--Display version number-->
    <TextView
        android:id="@+id/tv_version"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:textColor="@android:color/white"
        android:textSize="14sp"
        android:layout_centerInParent="true"/>
</RelativeLayout>

SplashActivity.java

Create the SplashActivity.java class and welcome the interface implementation class

package cn.edu.gdmec.android.androidstudiodemo;

import android.content.Intent;
import android.content.pm.ActivityInfo;
import android.content.pm.PackageInfo;
import android.content.pm.PackageManager;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.widget.TextView;
import java.util.Timer;
import java.util.TimerTask;

public class SplashActivity extends AppCompatActivity{
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_splash);
        //Set this interface as
        // Vertical screen
        setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
        init();
    }

    private void init() {
        TextView tv_version = findViewById(R.id.tv_version);
        try {
            PackageInfo packageInfo = getPackageManager().getPackageInfo(getPackageName(),0);
            tv_version.setText("version:"+packageInfo.versionName);
        } catch (PackageManager.NameNotFoundException e) {
            e.printStackTrace();
            tv_version.setText("version");
        }
        //Use timer to delay the interface for 3 seconds and then jump. Timer has a thread that continuously executes task s
        Timer timer = new Timer();
        TimerTask timerTask = new TimerTask() {
            @Override
            public void run() {
                //Send intent to realize page Jump. The first parameter is the context of the current page, and the second parameter is the homepage to jump
                Intent intent = new Intent(SplashActivity.this,MainActivity.class);
                startActivity(intent);
                //Close the current welcome page after jump
                SplashActivity.this.finish();
            }
        };
        //Scheduled execution timerTask, second parameter incoming delay time (MS)
        timer.schedule(timerTask,3000);
    }
}

AndroidManifest.xml

Configure the welcome interface in the list file Android manifest.xml, change the application entry to the welcome interface, and then remove the ActionBar effect

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="cn.edu.gdmec.android.androidstudiodemo">
    <!--originally be android:theme="@style/AppTheme"-->
    <!--Remove ActionBar Title Bar-->
    <!--Add app icon, app_icon-->
    <application
        android:allowBackup="true"
        android:icon="@drawable/app_icon"
        android:label="@string/app_name"
        android:roundIcon="@mipmap/ic_launcher_round"
        android:supportsRtl="true"
        android:theme="@style/Theme.AppCompat.NoActionBar">
        <activity android:name=".SplashActivity">
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />
                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
        <!--Add implementation class-->
        <activity android:name=".MainActivity"></activity>
    </application>
</manifest>

supplement

If the background image is added in the production process, you can find the relevant image to add or DIY alone. There are no changes in main activity.java and activity main.xml.

summary

  • This article talks about Android studio's production welcome interface and application icons. If you have a better understanding, welcome to communicate
  • Positioning: share Android & java knowledge points, if you are interested, you can continue to pay attention

Posted by 758 on Sat, 04 Apr 2020 19:18:39 -0700