您的位置:首页 > 移动开发

Android启动APP黑屏或白屏问题

2017-02-23 14:21 337 查看
在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的布局文件中的背景图与此处的一致即可。
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息