Android SplashActivity 启屏页最佳实践

启屏页最佳实践

1. 秒开:主题设置windowBackground,避免启动黑白闪屏

<style name="SplashTheme" parent="Theme.AppCompat.NoActionBar">
<item name="android:windowBackground">@mipmap/background_splash</item>
<item name="android:windowFullscreen">true</item>
</style>

2. 不设置setContentView,减少启动时间

3. 如何更改背景,比如显示首发:在原背景图上,制作一张带“首发”字体的图片,然后在增加一个style主题,然后在onCreate里setTheme()

4. 如何做postDelay后启动MainActivity

5. Show me the code:

public class SplashActivity extends Activity {

@Override
protected void onCreate(Bundle savedInstanceState) {
// setTheme(R.style.SplashThemeHuawei); // 更改背景
super.onCreate(savedInstanceState);
getWindow().getDecorView().postDelayed(new Runnable() {
@Override
public void run() {
startActivity(new Intent(SplashActivity.this, MainActivity.class));
finish();
}
}, 1000);
}

@Override
protected void onDestroy() {
super.onDestroy();
getWindow().getDecorView().getHandler().removeCallbacksAndMessages(null);
}
}

代码

参考项目内 android-library SplashActivty

参考: