別廢話了,直接上代碼:
1.manifest.xml中設(shè)置主題:
<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中準(zhǔn)備該主題:
<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><!--解決華為虛擬鍵盤遮住問(wèn)題-->
</style>
<style name="SplashTheme" parent="AppTheme">
<!-- 解決啟動(dòng)白屏的問(wèn)題 -->
<item name="android:windowBackground">@drawable/theme_splash</item>
<item name="android:windowFullscreen">true</item>
</style>
3.準(zhǔn)備好這個(gè)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>