Android开发冷启动解决白屏闪烁问题
参考文档
实现方法
1.通过延迟效果实现
1.创建主题样式
<!--启动解决空白问题方法2-->
<style name="Appwelcome" parent="android:Theme.Translucent.NoTitleBar.Fullscreen"/>
2.引导界面接入该主题(注意应用主题和引导界面主题的区分)
<activity android:name=".LeaderActivity"
android:theme="@style/Appwelcome"
tools:ignore="Instantiatable">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
3.如果报错需要再代码中进行主题设置处理.
protected void onCreate(@Nullable Bundle savedInstanceState) {
setTheme(R.style.AppTheme);
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_welcome);
2.通过设置一样的主题背景实现
1.创建主题格式
<!--启动解决空白问题-->
<style name="Theme.Start" parent="Theme.AppCompat.Light.NoActionBar">
<item name="android:windowBackground">@mipmap/lead_first</item>
<item name="android:windowNoTitle">true</item>
<item name="windowActionBar">false</item>
</style>
2.引导界面加入主题设置
<activity android:name=".LeaderActivity"
android:theme="@style/Theme.Start"
tools:ignore="Instantiatable">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
3.欢迎界面的处理,(延长欢迎界面显示时间,根据不同情况进入,例如首次和其他次进入欢迎界面不一样进行处理,)
protected void onCreate(@Nullable Bundle savedInstanceState) {
//setTheme(R.style.Theme_Start);
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_welcome);
new Handler().postDelayed(new Runnable() {
@Override
public void run() {
startActivity(new Intent(LeaderActivity.this, MainActivity.class));
finish();
}
}, 5000);
}