如何正確實(shí)現(xiàn)Android啟動(dòng)屏畫(huà)面的方法(避免白屏)
Android啟動(dòng)屏不正確的實(shí)現(xiàn)可能會(huì)導(dǎo)致用戶長(zhǎng)時(shí)間等待,或者可能會(huì)出現(xiàn)黑白屏。這里簡(jiǎn)單演示如何正確實(shí)現(xiàn)Android啟動(dòng)屏。
演示分為以下幾個(gè)步驟:
- 在res/drawable文件夾中創(chuàng)建splash_background.xml文件。
- 編輯res/values/styles.xml
- 創(chuàng)建java/.../SplashActivity
- 編輯manifests/AndroidManifest.xml
1、在res/drawable文件夾中創(chuàng)建splash_background.xml文件
根據(jù)你的需求調(diào)整位圖圖像的重力和尺寸。
<?xml version="1.0" encoding="utf-8"?> <layer-list xmlns:android="http://schemas.android.com/apk/res/android"> <item android:drawable="@color/colorPrimary"/> <item android:gravity="center" android:width="100dp" android:height="100dp"> <bitmap android:gravity="fill_horizontal|fill_vertical" android:src="@drawable/logo"/> </item> </layer-list>
2、編輯res/values/styles.xml
這里的樣式用于啟動(dòng)畫(huà)面。 這是為了在啟動(dòng)屏幕時(shí)隱藏操作欄。
<resources> <!-- Base application theme. --> <style name="AppTheme" parent="Theme.AppCompat.Light.NoActionBar"> <!-- Customize your theme here. --> <item name="colorPrimary">@color/colorPrimary</item> <item name="colorPrimaryDark">@color/colorPrimaryDark</item> <item name="colorAccent">@color/colorAccent</item> </style> <style name="SplashTheme" parent="Theme.AppCompat.Light.NoActionBar"> <item name="android:windowBackground">@drawable/splash_background</item> </style> </resources>
3、創(chuàng)建java/.../SplashActivity
一旦App啟動(dòng),SplashActivity將啟動(dòng),然后轉(zhuǎn)移到MainActivity。
package com.example.jtdan.goodSplash; import android.content.Intent; import android.os.Bundle; import android.support.v7.app.AppCompatActivity; public class SplashActivity extends AppCompatActivity { @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); //switch from splash activity to main activity Intent intent = new Intent(this, MainActivity.class); startActivity(intent); finish(); } }
4、編輯manifests/AndroidManifest.xml
在清單文件中添加新的啟動(dòng)畫(huà)面Activity。
<?xml version="1.0" encoding="utf-8"?> <manifest xmlns:android="http://schemas.android.com/apk/res/android" package="com.example.jtdan.goodSplash"> <application android:allowBackup="true" android:icon="@mipmap/ic_launcher" android:label="goodSplash" android:roundIcon="@mipmap/ic_launcher_round" android:supportsRtl="true" android:theme="@style/AppTheme"> <activity android:name="com.example.jtdan.goodSplash.SplashActivity" android:theme="@style/SplashTheme"> <intent-filter> <action android:name="android.intent.action.MAIN" /> <category android:name="android.intent.category.LAUNCHER" /> </intent-filter> </activity> <activity android:name="com.example.jtdan.goodSplash.MainActivity"></activity> </application> </manifest>
示例源碼地址:https://github.com/mrjoedang/goodSplash
以上就是本文的全部?jī)?nèi)容,希望對(duì)大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。
- Android編程之簡(jiǎn)單啟動(dòng)畫(huà)面實(shí)現(xiàn)方法
- Android簡(jiǎn)單實(shí)現(xiàn)啟動(dòng)畫(huà)面的方法
- Android編程中調(diào)用Camera時(shí)預(yù)覽畫(huà)面有旋轉(zhuǎn)問(wèn)題的解決方法
- Android啟動(dòng)畫(huà)面的實(shí)現(xiàn)方法
- Android開(kāi)機(jī)畫(huà)面的具體修改方法
- android Socket實(shí)現(xiàn)簡(jiǎn)單聊天功能以及文件傳輸
- 詳解Android——藍(lán)牙技術(shù) 帶你實(shí)現(xiàn)終端間數(shù)據(jù)傳輸
- Android實(shí)時(shí)獲取攝像頭畫(huà)面?zhèn)鬏斨罰C端思路詳解
相關(guān)文章
支持多項(xiàng)選擇的ExpandableListView
這篇文章主要為大家詳細(xì)介紹了支持多項(xiàng)選擇的ExpandableListView,具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2018-06-06Android延遲實(shí)現(xiàn)的幾種解決方法及原理分析
這篇文章主要給大家介紹了關(guān)于Android延遲實(shí)現(xiàn)的幾種解決方法以及其中的原理分析,文中通過(guò)示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來(lái)一起學(xué)習(xí)學(xué)習(xí)吧。2017-12-12Android通過(guò)自定義View實(shí)現(xiàn)隨機(jī)驗(yàn)證碼
這篇文章主要介紹了Android通過(guò)自定義View實(shí)現(xiàn)隨機(jī)驗(yàn)證碼的相關(guān)資料,需要的朋友可以參考下2016-03-03flutter中的網(wǎng)絡(luò)請(qǐng)求數(shù)據(jù)獲取詳解
這篇文章主要為大家介紹了flutter中的網(wǎng)絡(luò)請(qǐng)求數(shù)據(jù)獲取示例詳解,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進(jìn)步,早日升職加薪2023-01-01Android調(diào)用系統(tǒng)照相機(jī)拍照與攝像的方法
這篇文章主要為大家詳細(xì)介紹了Android如何調(diào)用系統(tǒng)現(xiàn)有的照相機(jī)拍照與攝像,文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2018-04-04Android ContentProvider的實(shí)現(xiàn)及簡(jiǎn)單實(shí)例代碼
這篇文章主要介紹了Android ContentProvider的實(shí)現(xiàn)及簡(jiǎn)單實(shí)例代碼的相關(guān)資料,需要的朋友可以參考下2017-02-02Android 7.0以上版本實(shí)現(xiàn)應(yīng)用內(nèi)語(yǔ)言切換的方法
本篇文章主要介紹了Android 7.0以上版本實(shí)現(xiàn)應(yīng)用內(nèi)語(yǔ)言切換的方法,小編覺(jué)得挺不錯(cuò)的,現(xiàn)在分享給大家,也給大家做個(gè)參考。一起跟隨小編過(guò)來(lái)看看吧2018-02-02解決webview內(nèi)的iframe中的事件不可用的問(wèn)題
這篇文章主要介紹了解決webview內(nèi)的iframe中的事件不可用的問(wèn)題,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。一起跟隨小編過(guò)來(lái)看看吧2020-03-03