完成记账本的启动界面
LauncherActivity文件:
1 package com.example.application_keep; 2 3 import androidx.appcompat.app.AppCompatActivity; 4 5 import android.app.Activity; 6 import android.content.Intent; 7 import android.os.Bundle; 8 import android.os.Handler; 9 10 public class LauncherActivity extends Activity { 11 12 @Override 13 protected void onCreate(Bundle savedInstanceState) { 14 super.onCreate(savedInstanceState); 15 setContentView(R.layout.activity_launcher); 16 new Handler().postDelayed(new Runnable() { 17 @Override 18 public void run() { 19 //在主线程中执行 20 startMainActivity(); 21 } 22 },2000); 23 } 24 //启动主页面 25 private void startMainActivity(){ 26 Intent intent=new Intent(this,MainActivity.class); 27 startActivity(intent); 28 //关闭当前页面 29 finish(); 30 } 31 }
activity_launcher.xml文件:
1 <?xml version="1.0" encoding="utf-8"?> 2 <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 3 xmlns:app="http://schemas.android.com/apk/res-auto" 4 xmlns:tools="http://schemas.android.com/tools" 5 android:layout_width="match_parent" 6 android:layout_height="match_parent" 7 android:background="@android:color/white" 8 tools:context=".LauncherActivity"> 9 10 <ImageView 11 android:id="@+id/la_icon" 12 android:layout_width="wrap_content" 13 android:layout_height="wrap_content" 14 android:src="@drawable/ks" 15 16 android:layout_centerInParent="true" 17 /> 18 19 <TextView 20 android:layout_width="wrap_content" 21 android:layout_height="wrap_content" 22 android:layout_below="@id/la_icon" 23 android:layout_marginTop="-48dp" 24 android:text="家庭记账本" 25 android:layout_centerHorizontal="true" 26 android:textColor="@android:color/black" 27 android:textSize="35sp" /> 28 </RelativeLayout>
需要注意的是,要在AndroidManifest文件中将LauncherActivity设置为启动界面
效果:
启动APP时,出现启动界面,3秒后关闭