制作启动动画
第一步:新建活动 new->Activity->Empty Activity 起名splash
第二步:下载图片 粘贴到drawable文件下
第三步:添加imageview布局到activity_splash.xml文件下
第四步:在SplashActivity写入一下代码
package com.example.myapplication; import androidx.appcompat.app.AppCompatActivity; import android.content.Intent; import android.os.Bundle; import android.view.WindowManager; 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 myThread = new Thread(){ //创建子线程 @Override public void run() { try { sleep(3000); //使程序休眠3秒 Intent it = new Intent(SplashActivity.this,MainActivity.class); //启动MainActivity startActivity(it); finish(); //关闭当前活动 } catch (InterruptedException e) { e.printStackTrace(); } } }; myThread.start(); } }
第五步:
<?xml version="1.0" encoding="utf-8"?> <manifest xmlns:android="http://schemas.android.com/apk/res/android" package="com.example.myapplication"> <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=".MainActivity"></activity> <activity android:name=".SplashActivity"> <intent-filter> <action android:name="android.intent.action.MAIN" /> <category android:name="android.intent.category.LAUNCHER" /> </intent-filter> </activity> </application> </manifest>