Android冷啟動實現(xiàn)app秒開的實現(xiàn)代碼
本文介紹了Android冷啟動實現(xiàn)app秒開的實現(xiàn)代碼,分享給大家,具體如下:
AndroidManifest里對應activity添加屬性android:theme="@style/AppSplash"
<activity
android:name="com.senyint.edu.college.stu.view.activity.SplashActivity"
android:screenOrientation="portrait"
android:theme="@style/AppSplash">
<intent-filter>
<action android:name="android.intent.action.MAIN"/>
<category android:name="android.intent.category.LAUNCHER"/>
</intent-filter>
</activity>
@style/AppSplash:
<style name="AppSplash" parent="Theme.AppCompat.Light.NoActionBar">
<item name="android:windowFullscreen">true</item>
<item name="android:windowBackground">@drawable/splash</item>
</style>
@drawable/splash:
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
<item>
<bitmap
android:src="@mipmap/splash"/>
</item>
</layer-list>
如此這樣便可以了,當然這只是給用戶的一種感覺,并不是真的“秒開”app。
在一個Activity打開時,如果該Activity所屬的Application還沒有啟動,那么系統(tǒng)會為這個Activity創(chuàng)建一個進程,在進程的創(chuàng)建和初始化中,會消耗一些時間,在這個時間里,WindowManager會先加載APP里的主題樣式里的窗口背景(windowBackground)作為預覽元素,然后才去真正的加載布局。而我上文所做的就是把啟動的界面放在style的windowBackground配置里作為預覽元素呈現(xiàn)給用戶。
以上就是本文的全部內容,希望對大家的學習有所幫助,也希望大家多多支持腳本之家。
相關文章
Android實現(xiàn)Toast提示框圖文并存的方法
這篇文章主要介紹了Android實現(xiàn)Toast提示框圖文并存的方法,實例分析了Toast提示框的參數(shù)設置及圖文調用的相關技巧,需要的朋友可以參考下2016-01-01
android 字體顏色選擇器(ColorPicker)介紹
本文將詳細介紹android 字體顏色選擇器(ColorPicker)需要了解更多的朋友可以參考下2012-11-11
Android開發(fā)中使用Volley庫發(fā)送HTTP請求的實例教程
這篇文章主要介紹了Android開發(fā)中使用Volley庫發(fā)送HTTP請求的實例教程,包括創(chuàng)建Volley單例的基本知識與取消Request請求的技巧等,需要的朋友可以參考下2016-05-05
Android中監(jiān)聽系統(tǒng)網(wǎng)絡連接打開或者關閉的實現(xiàn)代碼
本篇文章對Android中監(jiān)聽系統(tǒng)網(wǎng)絡連接打開或者關閉的實現(xiàn)用實例進行了介紹。需要的朋友參考下2013-05-05

