概述
android開(kāi)發(fā)者應(yīng)該都有這樣的體會(huì):開(kāi)發(fā)到一定的階段,包變得很大了,每次啟動(dòng)APP的時(shí)候,總是有白屏一閃而過(guò)(白屏的時(shí)間和包的大小成正比),這篇文章就是解決這個(gè)問(wèn)題.
上代碼
第一步:在style文件中自定義一個(gè)customTheme,繼承啟動(dòng)頁(yè)的theme,重寫(xiě)windowBackground屬性設(shè)為自定義的一張啟動(dòng)圖片
<resources>
<!-- Base application theme. -->
<style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
<!-- Customize your theme here. -->
<item name="colorPrimary">@color/colorPrimary</item>
<item name="colorPrimaryDark">@color/colorPrimaryDark</item>
<item name="colorAccent">@color/colorAccent</item>
</style>
<!--parent設(shè)置為啟動(dòng)頁(yè)的theme-->
<style name="AppTheme.customeTheme" parent="AppTheme">
<item name="android:windowBackground">@drawable/wx_launch</item>
</style>
</resources>
第二步:在manifest文件中將啟動(dòng)頁(yè)(activity)的theme設(shè)為自定義的customTheme.
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.xiao.custom_launch">
<application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="@style/AppTheme">
<!--啟動(dòng)activity的theme設(shè)為自定義的customeTheme-->
<activity android:name=".MainActivity"
android:theme="@style/AppTheme.customeTheme">
<intent-filter>
<action android:name="android.intent.action.MAIN"/>
<category android:name="android.intent.category.LAUNCHER"/>
</intent-filter>
</activity>
</application>
</manifest>
簡(jiǎn)單的兩步,就可以將啟動(dòng)時(shí)一閃而過(guò)的白屏替換為自己的圖片(比如帶公司logo的圖片).