天天看點

Android 程式設計日記 解決應用啟動時白屏或者黑屏的問題

解決應用啟動時白屏或者黑屏的問題

由于Activity隻能到onResume時,才能展示到前台,是以,如果為MAIN activity設定背景的話,無論onCreate-onResume速度多快,都會出現短暫的白屏或者黑屏 

其實解決的辦法很簡單,隻需将你的Startup Activity中的View的background屬性删除(mainLayout.xml 中的background屬性删除),

然後在AndroidManifest.xml為你的Startup Activity加上theme屬性即可

theme的xml在res/values/styles.xml 下

<resources>

    <stylename="AppTheme"parent="android:Theme.Light">

    <itemname="android:windowBackground">@null</item>//@null黑屏  @drawable/icon放一張啟動圖檔

    <itemname="android:windowNoTitle">true</item> //啟動界面是否顯示應用名稱 true不顯示 false顯示

</style>

 </resources>

AndroidManifest.xml裡面

   <activityandroid:name=".openframework"

                  android:label="@string/app_name"

                  android:screenOrientation="portrait"

                  android:theme= "@style/AppTheme" 

                  android:configChanges="orientation">

            <intent-filter>

                <actionandroid:name="android.intent.action.MAIN"/>

                <categoryandroid:name="android.intent.category.LAUNCHER"/>

            </intent-filter>

        </activity>