App在啓動時,即在歡迎界面。老是出現白屏或黑屏,閃一下然後纔出現歡迎界面。
我歡迎界面原先是這樣的:
<?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="match_parent" android:background="@mipmap/bg_welcome" android:orientation="vertical"> </LinearLayout>
把圖片直接設置爲背景,由於Activity只能到onResume時,才能展示到前臺。所以這樣直接設置爲背景是會出現閃屏的,其實也不是閃屏,而是Activity的Style(白色或黑色);
是這樣解決的:
首先 去掉圖片設爲背景,即空白layout;
定義一個Style 擴展自AppTheme,並設定windowBackground爲需要顯示的背景圖片
<!-- Base application theme. --> <style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar"> <!-- Customize your theme here. --> <item name="colorPrimary">#8CC24F</item> <item name="colorPrimaryDark">#8CC24F</item> <item name="colorAccent">@color/colorAccent</item> </style> <style name="WelcomeTheme" parent="AppTheme"> <item name="android:windowBackground">@mipmap/bg_welcome</item> </style>
3.在Activity配置中引用
<activity android:name=".AtyWelcome" android:theme="@style/WelcomeTheme"> <intent-filter> <action android:name="android.intent.action.MAIN" /> <category android:name="android.intent.category.LAUNCHER" /> </intent-filter> </activity>
到此已經解決了App啓動閃屏問題;
轉載請註明出處: