Android啟動頁優(yōu)化之實現(xiàn)應(yīng)用秒開
Android 應(yīng)用冷啟動時,需要從Application開始啟動,加載時間就會比較長,這段時間里,用戶所能看到的就是”白屏“(這是因為默認(rèn)的AppTheme的 android:windowBackground 默認(rèn)是設(shè)置成白色的),因此我認(rèn)為真正的啟動頁就應(yīng)該是讓用戶點開應(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="@drawable/ic_logo" android:gravity="center"/> </item> </layer-list>
我們使用 layer-list 標(biāo)簽創(chuàng)建一個圖層列表,實際就是一個 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)化之實現(xiàn)應(yīng)用秒開的詳細(xì)內(nèi)容,更多關(guān)于Android 實現(xiàn)應(yīng)用秒開的資料請關(guān)注腳本之家其它相關(guān)文章!
相關(guān)文章
android配合viewpager實現(xiàn)可滑動的標(biāo)簽欄示例分享
本文主要介紹了android實現(xiàn)可滑動的標(biāo)簽欄示例,配合viewpager作為標(biāo)簽欄,且可以設(shè)置每頁顯示的標(biāo)簽個數(shù),超出可滑動顯示,需要的朋友可以參考下2014-02-02Kotlin協(xié)程Dispatchers原理示例詳解
這篇文章主要為大家介紹了Kotlin協(xié)程Dispatchers原理示例詳解,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進(jìn)步,早日升職加薪2022-08-08Android?通過productFlavors實現(xiàn)多渠道打包方法示例
這篇文章主要為大家介紹了Android?通過productFlavors實現(xiàn)多渠道打包方法示例詳解,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進(jìn)步,早日升職加薪2023-02-02Android使用ViewDragHelper實現(xiàn)QQ聊天氣泡拖動效果
這篇文章主要為大家詳細(xì)介紹了Android使用ViewDragHelper實現(xiàn)QQ聊天氣泡拖動效果,文中示例代碼介紹的非常詳細(xì),具有一定的參考價值,感興趣的小伙伴們可以參考一下2019-01-01