為您解碼網(wǎng)站建設(shè)的點(diǎn)點(diǎn)滴滴
發(fā)表日期:2018-12 文章編輯:小燈 瀏覽次數(shù):3300
Android App 一般在啟動(dòng)的時(shí)候會(huì)出現(xiàn)白屏、黑屏,持續(xù) 0.5s - 3s (看 App 啟動(dòng)加載復(fù)雜度 與 手機(jī)性能)。
其主要的原因是默認(rèn)的 Andraid App 是沒有設(shè)置啟動(dòng)圖的。在啟動(dòng)的時(shí)候,Andraid App 需要加載各種資源,包括創(chuàng)建 Activity 等。
如果第一個(gè)Activity,還沒創(chuàng)建完成,就會(huì)看到白屏、黑屏,一般解決這個(gè)問題就是為 Andraid App 設(shè)置一個(gè)啟動(dòng)圖。就像淘寶 App 那樣,啟動(dòng)的時(shí)候會(huì)看到一張關(guān)于淘寶的圖片。
而 iOS App 默認(rèn)設(shè)置了啟動(dòng)圖,就不會(huì)像 Android App 那樣出現(xiàn)白屏、黑屏。
在打開 Flutter App 時(shí)會(huì)出現(xiàn)短暫的白屏現(xiàn)象(Android),這并不是 Flutter 的特例,在 React Native 上同樣如此。因此在 React Native 上解決白屏的處理方式與 Flutter 類似。
在 xml 里,添加啟動(dòng)圖。當(dāng) App 打開時(shí)會(huì)先看到啟動(dòng)圖,接著渲染 Flutter 所管理的 Activity。
首先在 android/app/src/main/res/drawable-hdpi
里加上一個(gè)圖片作為程序啟動(dòng)圖(名稱隨意,例如:bg.png),然后修改 android/app/src/main/res/values/styles.xml
。
<style name="AppTheme" parent="Theme.AppCompat.Light.NoActionBar"> <!-- 這里將剛剛那張圖片設(shè)置為背景圖片, bg對(duì)應(yīng)圖片名稱 --> <item name="android:windowBackground">@drawable/bg</item> </style>
或者,在 android\app\src\main\res\drawable\launch_background.xml
里添加,也行。
<?xml version="1.0" encoding="utf-8"?> <!-- Modify this file to customize your launch splash screen --> <layer-list xmlns:android="http://schemas.android.com/apk/res/android"> <item android:drawable="@android:color/white" /><!-- You can insert your own image assets here --> <item> <bitmap android:gravity="center" android:src="@mipmap/bg" /> </item> </layer-list>
最后,記得在 Flutter 底端頁面上設(shè)置背景為非透明。
@override Widget build(BuildContext context) { return new Scaffold( appBar: new AppBar( title: new Text('應(yīng)用'), ), body: new Container( color: Colors.white, ), ); }