Android启动APP黑屏或白屏问题

在App开发中一般都有一个欢迎页SplashActivity,有时候我们会发现启动APP一段时间黑屏或者白屏后,才会显示欢迎图案或GIF,出现这种问题的主要原因是还没加载到splash的布局文件,就显示了window的窗口背景了,其实现在的app都集成比较多的三方框架,所以在application中进行比较多的初始化操作,这种现象也比较常见。
解决的办法主要是通过style中设置window与splash相同的背景图即可:

<style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
        <!-- Customize your theme here. -->
        <item name="colorPrimary">@color/colorPrimary</item>
        <item name="colorPrimaryDark">@color/colorPrimary</item>
        <item name="colorAccent">@color/colorAccent</item>
        <item name="android:windowBackground">@color/color_bg</item>
    </style>

    <style name="Fullscreen" parent="Theme.AppCompat">
        <item name="android:windowFullscreen">true</item>
        <item name="android:windowBackground">@mipmap/welcome</item>
    </style>

以上两个style中AppTheme为其他activity的style,而Fullscreen为splash的style。

<activity
            android:name=".SplashActivity"
            android:screenOrientation="portrait"
            android:theme="@style/Fullscreen">
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />
                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>

注意在SplashActivity的布局文件中的背景图与此处的一致即可。

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值