在清单文件中配置
//启动页
<activity android:name=".activity.LunachActivity">
android:screenOrientation="portrait"
android:theme="@style/AppTheme.NoTitle.Fullscreen">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
LaunchActivity.java
public class LunachActivity extends AppCompatActivity {
private static final long SPLASH_DELAY_MILLIS = 3000;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_lunach);
// 使用Handler的postDelayed方法,3秒后执行跳转到MainActivity
new Handler().postDelayed(new Runnable() {
public void run() {
goHome();
}
}, SPLASH_DELAY_MILLIS);
}
private void goHome() {
Intent intent = new Intent(LunachActivity.this, MainActivity.class);
LunachActivity.this.startActivity(intent);
LunachActivity.this.finish();
}
}