1.解决App启动之后短暂的空白画面(白屏或者黑屏,和自己使用的主体有关),在style中使用
<!-- Base application theme-->
<style name="AppTheme" parent="Theme.AppCompat.Light.NoActionBar">
<!-- Customize your theme here. -->
<item name="colorPrimary">@color/colorPrimary</item>
<item name="colorPrimaryDark">@color/colorPrimaryDark</item>
<item name="colorAccent">@color/colorAccent</item>
</style>
<!--全屏-->
<style name="AppTheme.FullScreen" parent="AppTheme">
<!--ActionBar 隐藏 下面两个一起使用-->
<item name="windowActionBar">false</item>
<item name="windowNoTitle">true</item>
<!--状态栏透明-->
<item name="android:windowTranslucentStatus">true</item>
<!--导航栏透明 华为手机虽然透明但依然可见图标,-->
<item name="android:windowTranslucentNavigation">true</item>
<!--全屏-->
<item name="android:windowFullscreen">true</item>
<!-- 是否允许背景灰暗 -->
<item name="android:backgroundDimEnabled">false</item>
</style>
<!--解决启动画面背景是白屏或者黑屏的尴尬-->
<style name="AppTheme.Splash" parent="AppTheme.FullScreen">
<item name="android:background">@drawable/bg_splash</item>
</style>
上面的 全屏styel使用之后,还是会看到导航栏透明,为了让全屏更加彻底,需要在java代码中设置一下:
public static void hideSystemUi(Window window) {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
window.getDecorView().setSystemUiVisibility(View.SYSTEM_UI_FLAG_LAYOUT_STABLE
| View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION
| View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN
| View.SYSTEM_UI_FLAG_FULLSCREEN
| View.SYSTEM_UI_FLAG_HIDE_NAVIGATION
| View.SYSTEM_UI_FLAG_IMMERSIVE);
}
}
另外 设置android:background的时候,一定要使用drawable中的图片资源,否则没有效果;