1. 程式人生 > >解決Android app啟動白屏問題

解決Android app啟動白屏問題

1.解決app啟動白屏問題 介紹兩種方式

  1. 載入首頁頁面前,進行頁面或者顏色過渡,使用者體驗感好
    第一步設定一下主題色為透明

     <!-- 應用啟動頁(StartingWindow)的theme -->
        <style name="AppTheme.StartingWindowTheme" parent="AppTheme">
            <item name="android:windowIsTranslucent">true</item>
        </style>

    第二步,在啟動的activity設定一下主題theme
     

     <activity
                android:name=".ui.activity.NavigationActivity"
                android:theme="@style/AppTheme.StartingWindowTheme"
                android:screenOrientation="portrait">
                <intent-filter>
                    <action android:name="android.intent.action.MAIN" />
    
                    <category android:name="android.intent.category.LAUNCHER" />
                </intent-filter>
            </activity>

    第三布,在載入完成頁面的時候,設定為以前的theme
     

     override fun onCreate(savedInstanceState: Bundle?, persistentState: PersistableBundle?) {
            super.onCreate(savedInstanceState, persistentState)
            setTheme(R.style.AppTheme)//恢復原有的樣式
        }

     

  2. 載入首頁頁面前,進行透明顯示,點選桌面圖示,卡頓一下進入首頁
    第一步設定一下主題 為一張圖片背景或者顏色
     

    <!-- 應用啟動頁(StartingWindow)的theme -->
        <style name="AppTheme.StartingWindowTheme" parent="AppTheme">
            <!-- 可以設定成純顏色(設定一個和Activity UI相似的背景) -->
            <!--<item name="android:windowBackground">@color/blue_home</item>-->
            <!--也可以設定成一張圖片 -->
            <!--<item name="android:windowBackground">@drawable/bgbg</item>-->
        </style>

    第二步和第三步一樣

  3. 參考文件
    http://ju.outofmemory.cn/entry/356791
    http://www.cnblogs.com/whycxb/p/9312914.html