国产成人精品亚洲777人妖,欧美日韩精品一区视频,最新亚洲国产,国产乱码精品一区二区亚洲

您的位置:首頁技術(shù)文章
文章詳情頁

Android啟動頁優(yōu)化之實(shí)現(xiàn)應(yīng)用秒開

瀏覽:61日期:2022-09-18 14:55:58

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://www.intensediesel.com/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)文章!

標(biāo)簽: Android
相關(guān)文章:
主站蜘蛛池模板: 梁平县| 兴化市| 南京市| 湟源县| 阳西县| 任丘市| 建宁县| 丰县| 刚察县| 梁河县| 丰镇市| 晋城| 沙雅县| 桐柏县| 博湖县| 昌平区| 洛宁县| 湖州市| 无棣县| 故城县| 曲靖市| 濮阳市| 天门市| 克拉玛依市| 武乡县| 民和| 濮阳县| 阿图什市| 上高县| 南昌县| 南丹县| 江陵县| 历史| 枞阳县| 桃源县| 乐山市| 水富县| 肇源县| 桦甸市| 丰城市| 景泰县|