Android APP啟動(dòng)白屏優(yōu)化

概述

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的圖片).

最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時(shí)請(qǐng)結(jié)合常識(shí)與多方信息審慎甄別。
平臺(tái)聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡(jiǎn)書(shū)系信息發(fā)布平臺(tái),僅提供信息存儲(chǔ)服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

友情鏈接更多精彩內(nèi)容