導(dǎo)讀
app啟動(dòng)的時(shí)候,會(huì)有一個(gè)閃屏頁(yè)好乐,英文叫SplashActivity蛔溃。當(dāng)點(diǎn)擊應(yīng)用圖標(biāo)绰沥,閃屏頁(yè)如果不經(jīng)過(guò)特別處理篱蝇,會(huì)出現(xiàn)一小刻的白屏。
出現(xiàn)這個(gè)問(wèn)題的原因是因?yàn)閺膯?dòng)應(yīng)用到Activity閃屏也的onResume方法執(zhí)行 的時(shí)間會(huì)比較耗時(shí)徽曲。
解決方法
我們把閃屏頁(yè)的背景和圖標(biāo)可以設(shè)置在style里零截。這個(gè)style又是和Activity注冊(cè)在AndroidManifest里的。
上代碼
1.logo.xml
<layer-list xmlns:android="http://schemas.android.com/apk/res/android" >
<item>
<shape android:shape="rectangle" >
<solid android:color="#f45232" />
</shape>
</item>
<item android:bottom="48dp">
<bitmap
android:gravity="center"
android:src="@drawable/hello" />
</item>
</layer-list
第一個(gè)item:設(shè)置背景色
第一個(gè)item:居中的圖片可以直接展示出來(lái)
2.將其作為我們當(dāng)前Activity的windowBackground
<style
name="Theme2"
parent="AppTheme" >
<item name="android:windowBackground">@drawable/logo</item>
</style>
3.設(shè)置到Activity上:
<activity
android:name=".activity.WhiteScreenActivity2"
android:theme="@style/Theme2">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
源碼參考我的github地址