【Android】APP白屏解决

2020-07-08  本文已影响0人  urkay

打开app的时候,会有短暂的1秒--2秒的白屏,然后才进入到程序界面。

解决方法很简单,修改下启动页的主题,如下:

styles.xml新建主题,重点是android:windowBackground设置成想要的图片

    <style name="AppTheme.NoActionBar">
        <item name="windowActionBar">false</item>
        <item name="windowNoTitle">true</item>
        <item name="android:windowBackground">@mipmap/pic_guide</item>
        <item name="android:windowFullscreen">true</item>
    </style>

启动页Activity设置主题(android:theme),刚新建的style

        <activity
            android:name=".ui.activity.GuideActivity"
            android:theme="@style/AppTheme.NoActionBar">
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />
                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>

使用Intent.FLAG_ACTIVITY_CLEAR_TASK | Intent.FLAG_ACTIVITY_NEW_TASK
进行Activity跳转回出现白屏,需要增加windowDisablePreview这个主题属性

 <activity
            android:name=".MainActivity"
            android:theme="@style/AppTheme.NoActionBar"
            android:screenOrientation="portrait"
            android:windowSoftInputMode="adjustPan" />

    <style name="AppTheme.NoActionBar">
        <item name="windowActionBar">false</item>
        <item name="windowNoTitle">true</item>
        <item name="android:windowDisablePreview">true</item>
    </style>
上一篇下一篇

猜你喜欢

热点阅读