别废话了,直接上代码:
1.manifest.xml中设置主题:
<activity
android:name="com.zack.ownerclient.SplashActivtiy"
android:screenOrientation="portrait"
android:theme="@style/SplashTheme">
<intent-filter>
<action android:name="android.intent.action.MAIN"/>
<category android:name="android.intent.category.DEFAULT"/>
<category android:name="android.intent.category.LAUNCHER"/>
</intent-filter>
</activity>
2.styles中准备该主题:
<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>
<item name="android:windowDrawsSystemBarBackgrounds">false</item><!--解决华为虚拟键盘遮住问题-->
</style>
<style name="SplashTheme" parent="AppTheme">
<!-- 解决启动白屏的问题 -->
<item name="android:windowBackground">@drawable/theme_splash</item>
<item name="android:windowFullscreen">true</item>
</style>
3.准备好这个drawable:theme_splash.xml
<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
<!-- 背景颜色 -->
<item android:drawable="@drawable/img_start_bg" />
<item >
<bitmap
android:gravity="center"
android:id="@+id/bitmap_splash"
android:src="@drawable/img_start_logo">
</bitmap>
</item>
</layer-list>