Android 12 增加了系统默认的 APP 启动页,该 APP 启动页会使用APP定义的主题和ICON生成,如何设置查看以下链接:
Android 12 适配简介
但是在如何设置启动页的显示时长上,可以用如下方法设置:
package com.ycl.android31test;
import androidx.appcompat.app.AppCompatActivity;
import androidx.core.splashscreen.SplashScreen;
import android.os.Bundle;
import android.os.Handler;
public class MainActivity extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
// Handle the splash screen transition.
SplashScreen splashScreen = SplashScreen.installSplashScreen(this);
splashScreen.setKeepVisibleCondition( new SplashScreen.KeepOnScreenCondition() {
@Override
public boolean shouldKeepOnScreen() {
return true;
}
});
setContentView(R.layout.activity_main);
new Handler().postDelayed(new Runnable() {
@Override
public void run() {
splashScreen.setKeepVisibleCondition( new SplashScreen.KeepOnScreenCondition() {
@Override
public boolean shouldKeepOnScreen() {
return false;
}
});
}
},3000);
}
}
这样操作就使得开屏页能够停留三秒钟。
关于如何在android 12利用谷歌官方的API来设置开屏页,参考如下链接: