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

