WindowBackground打造闪屏页
在创建app的时候Android会立即显示一个backgroundwindow,然后再去创建app进程。这就会产生刚开始打开app的时候出现白屏现象。这篇文章就是为了解决这个白屏现象,如下几步轻松实现闪屏页。
- 1、新建SplashTheme style
- 2、在你的app起始页设置style风格
- 3、设置页面跳转
新建SplashTheme style
<style name="SplashTheme" parent="AppTheme">
<item name="android:windowIsTranslucent">false</item>
<item name="android:background">@mipmap/we</item>
<item name="android:windowFullscreen">true</item>
</style>
在你的app起始页设置style风格
<activity
android:name=".ui.WelcomeActivity"
android:theme="@style/SplashTheme"
android:configChanges="orientation|screenSize">
<intent-filter>
<actionandroid:name="android.intent.action.MAIN"/>
<categoryandroid:name="android.intent.category.LAUNCHER"/>
</intent-filter>
</activity>
设置页面跳转
public class WelcomeActivity extends FragmentActivity {
@Override
protected void onCreate(@Nullable Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
getWindow().setFlags(
WindowManager.LayoutParams.FLAG_FULLSCREEN,
WindowManager.LayoutParams.FLAG_FULLSCREEN);
/*采用handler创建子线程实现页面跳转*/
new Handler().postDelayed(new Runnable() {
@Override
public void run() {
Intent intent =new Intent(WelcomeActivity.this,LoginActivity.class);
startActivity(intent);
WelcomeActivity.this.finish();
}
},1000);
}
}
注意一点的是设置该welcomeActivity的style后只能结束这个activity
详细代码。具体请参考GitHub(https://github.com/zct1115/MyLoginApplication)