windowBackground打造闪屏页

windowBackgroud关键在于设置背景图片或者动态drawable。如下步骤轻松实现闪屏页
1、
在styles下新建一个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>
 
2、在你的app起始页设置style风格
<activity
    android:name=".ui.WelcomeActivity"
    android:theme="@style/SplashTheme"
    android:configChanges="orientation|screenSize">
    <intent-filter>
        <action android:name="android.intent.action.MAIN" />
 
        <category android:name="android.intent.category.LAUNCHER" />
    </intent-filter>
</activity>
 
3、因为设置了style风格所以要清楚这个回到AppTheme风格,需要在welcomeActivity设置
我在welcomeActivity设置线程结束该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。如果在welcomeActivity上设置setTheme(R.style.AppTheme);//不起作用
原文地址:https://www.cnblogs.com/zzl-0402/p/7366448.html