1 Splash頁面常用於啓動的頁面改善用戶體驗防止白屏頁面影響體驗
2 常見做法
創建splash頁面
SplashActivity
設置theme
在styles.xml文件中設置頁面的主題
代碼如下:
<style name="SplashTheme" parent="Theme.AppCompat.Light.NoActionBar">
<item name="android:windowBackground">@mipmap/icon_splash</item>
<item name="android:windowDrawsSystemBarBackgrounds">true</item>
<item name="android:windowContentOverlay">@null</item>
<item name="android:windowFullscreen">false</item>
<item name="android:windowNoTitle">true</item>
</style>
其中windowBackground設置的是啓動的畫面對應的圖片
設置Androidmanifest的啓動頁爲splash頁面
<!--開屏頁面-->
<activity
android:theme="@style/SplashTheme"
android:name=".splash.SplashActivity" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
注意:
<item name="android:windowDrawsSystemBarBackgrounds">true</item>
這個屬性如果設置爲false的話,畫面會有跳動,整個畫面會向下移動一個狀態欄高度的位置。