Android啟動頁優(yōu)化之實(shí)現(xiàn)應(yīng)用秒開
Android 應(yīng)用冷啟動時,需要從Application開始啟動,加載時間就會比較長,這段時間里,用戶所能看到的就是”白屏“(這是因?yàn)槟J(rèn)的AppTheme的 android:windowBackground 默認(rèn)是設(shè)置成白色的),因此我認(rèn)為真正的啟動頁就應(yīng)該是讓用戶點(diǎn)開應(yīng)用時看到的不是”白屏“,而是我們創(chuàng)建的一個頁面,可以是一張圖片、一段文字。這樣,不明真相的用戶直觀感覺到的就是,這個應(yīng)用可以秒開。
1.首先在 drawable 目錄下新建一個 splash_screen.xml 文件<?xml version='1.0' encoding='utf-8'?><layer-list xmlns:android='http://schemas.android.com/apk/res/android' android:opacity='opaque'> <item android:drawable='@color/colorPrimary'/> <item><bitmap android:src='http://m.cgvv.com.cn/bcjs/@drawable/ic_logo' android:gravity='center'/> </item></layer-list>
我們使用 layer-list 標(biāo)簽創(chuàng)建一個圖層列表,實(shí)際就是一個 LayerDrawable ,設(shè)置一個背景,然后放上應(yīng)用圖標(biāo),這是我想展示的啟動頁,可以根據(jù)自己的需要自行定義。
2.然后在 style.xml 文件中定義一個 SplashTheme<resources> ...<style name='SplashTheme' parent='AppTheme'><item name='android:windowBackground'>@drawable/splash_screen</item> </style></resources>
這里只需要將窗口背景設(shè)置為我們剛才定義的 LayerDrawable。
3.然后需要在 AndroidMenifest.xml 文件中將我們的主頁面,我這里是 MainActivity 的 android:theme 設(shè)置成我們定義的SplashTheme<?xml version='1.0' encoding='utf-8'?><manifest xmlns:android='http://schemas.android.com/apk/res/android' xmlns:tools='http://schemas.android.com/tools' ... > ... <application... ><activity android:name='.activity.MainActivity' android:launchMode='singleTask' android:theme='@style/SplashTheme'> <intent-filter><action android:name='android.intent.action.MAIN' /><category android:name='android.intent.category.LAUNCHER' /> </intent-filter></activity>... </application></manifest>
是不是很簡單這樣就可以了
以上就是Android啟動頁優(yōu)化之實(shí)現(xiàn)應(yīng)用秒開的詳細(xì)內(nèi)容,更多關(guān)于Android 實(shí)現(xiàn)應(yīng)用秒開的資料請關(guān)注好吧啦網(wǎng)其它相關(guān)文章!
相關(guān)文章:
1. HTTP協(xié)議常用的請求頭和響應(yīng)頭響應(yīng)詳解說明(學(xué)習(xí))2. IntelliJ IDEA創(chuàng)建web項(xiàng)目的方法3. 在vue項(xiàng)目中引用Antv G2,以餅圖為例講解4. python實(shí)現(xiàn)與redis交互操作詳解5. ASP.NET MVC通過勾選checkbox更改select的內(nèi)容6. 存儲于xml中需要的HTML轉(zhuǎn)義代碼7. Python多線程實(shí)現(xiàn)支付模擬請求過程解析8. ASP中實(shí)現(xiàn)字符部位類似.NET里String對象的PadLeft和PadRight函數(shù)9. Python Request類源碼實(shí)現(xiàn)方法及原理解析10. Android studio 解決logcat無過濾工具欄的操作
