Android啟動(dòng)頁(yè)優(yōu)化之實(shí)現(xiàn)應(yīng)用秒開
Android 應(yīng)用冷啟動(dòng)時(shí),需要從Application開始啟動(dòng),加載時(shí)間就會(huì)比較長(zhǎng),這段時(shí)間里,用戶所能看到的就是”白屏“(這是因?yàn)槟J(rèn)的AppTheme的 android:windowBackground 默認(rèn)是設(shè)置成白色的),因此我認(rèn)為真正的啟動(dòng)頁(yè)就應(yīng)該是讓用戶點(diǎn)開應(yīng)用時(shí)看到的不是”白屏“,而是我們創(chuàng)建的一個(gè)頁(yè)面,可以是一張圖片、一段文字。這樣,不明真相的用戶直觀感覺到的就是,這個(gè)應(yīng)用可以秒開。
1.首先在 drawable 目錄下新建一個(gè) 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://www.leifengta.com.cn/bcjs/@drawable/ic_logo' android:gravity='center'/> </item></layer-list>
我們使用 layer-list 標(biāo)簽創(chuàng)建一個(gè)圖層列表,實(shí)際就是一個(gè) LayerDrawable ,設(shè)置一個(gè)背景,然后放上應(yīng)用圖標(biāo),這是我想展示的啟動(dòng)頁(yè),可以根據(jù)自己的需要自行定義。
2.然后在 style.xml 文件中定義一個(gè) SplashTheme<resources> ...<style name='SplashTheme' parent='AppTheme'><item name='android:windowBackground'>@drawable/splash_screen</item> </style></resources>
這里只需要將窗口背景設(shè)置為我們剛才定義的 LayerDrawable。
3.然后需要在 AndroidMenifest.xml 文件中將我們的主頁(yè)面,我這里是 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>
是不是很簡(jiǎn)單這樣就可以了
以上就是Android啟動(dòng)頁(yè)優(yōu)化之實(shí)現(xiàn)應(yīng)用秒開的詳細(xì)內(nèi)容,更多關(guān)于Android 實(shí)現(xiàn)應(yīng)用秒開的資料請(qǐng)關(guān)注好吧啦網(wǎng)其它相關(guān)文章!
相關(guān)文章:
1. IntelliJ IDEA安裝插件的方法步驟2. 理解PHP5中static和const關(guān)鍵字3. php模擬實(shí)現(xiàn)斗地主發(fā)牌4. spring acegi security 1.0.0 發(fā)布5. Vue封裝一個(gè)TodoList的案例與瀏覽器本地緩存的應(yīng)用實(shí)現(xiàn)6. Vuex localStorage的具體使用7. jQuery 實(shí)現(xiàn)DOM元素拖拽交換位置的實(shí)例代碼8. .Net Core使用Coravel實(shí)現(xiàn)任務(wù)調(diào)度的完整步驟9. vue 使用localstorage實(shí)現(xiàn)面包屑的操作10. MyBatis中的JdbcType映射使用詳解

網(wǎng)公網(wǎng)安備