1. 在res/drawable
下创建一个bg_splash.xml
文件,并写下下面的内容
其中@drawable/splas
是一张图片,来自drawable
文件夹下
其中@color/gray
是灰色,来自colors.xml
文件
<?xml version="1.0" encoding="utf-8"?>
<layer-list
<item android:drawable="@color/gray" />
<item>
<bitmap
android:src="@drawable/splash" />
</item>
</layer-list>
2. 在styles.xml
文件下创建SplashTheme的主题,引入bg_splash
<resources>
<!-- Base application theme. -->
<style name="AppTheme" parent="Theme.AppCompat.Light.NoActionBar">
<!-- Customize your theme here. -->
</style>
<style name="SplashTheme" parent="Theme.AppCompat.NoActionBar">
<item name="android:windowBackground">@drawable/bg_splash</item>
</style>
</resources>
3.在你的启动界面中引入SplashTheme
,如下
<activity
android:name=".SplashActivity"
android:theme="@style/SplashTheme">
android:noHistory="true">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>