美文网首页
Android 中启动页黑屏及白屏的解决方式

Android 中启动页黑屏及白屏的解决方式

作者: 用心感受世界 | 来源:发表于2017-06-01 16:58 被阅读0次

启动页黑屏或白屏的原因是,当Activity启动的时候不能马上加载layout。
而黑屏或者白屏是你的theme主题的默认样式,当layout没加载出来就显示黑屏或者白屏。

1.windowBackground 窗体背景为指定图片

我们可以人为的设置 Activity的Theme的这一属性 <item name="android:windowBackground"> 为指定的图片,这样Activity没有加载出来也可以显示启动页,不过这样就不能在layout中加其他东西了,启动页的layout.xml就不怎么好处理了。

2.windowIsTranslucent 窗体背景透明

又或者可以像微信一样处理,设置Activity的Theme背景为透明色
<item name="android:windowIsTranslucent">true</item>
使app看起来像没有启动一样,等到layout都加载完了才显示启动页,实际上早就启动了。
视觉效果是背景色是透明的,所以你觉得没有启动,这样启动虽慢,
但是layout可以自己决定有什么内容,看需求使用吧。

修改项目中 values/styles.xml

 <!--快速启动-->
    <style name="AppTheme.NoActionBarAndTitle" parent="FullScreenTheme">
        <item name="windowNoTitle">true</item>
        <item name="android:windowBackground">@mipmap/qdy2</item>

    </style>

    <!--全屏加透明,慢速启动-->
    <style name="TranslucentFullScreenTheme" parent="FullScreenTheme">
        <item name="android:windowBackground">@color/transparent</item>
        <item name="android:windowIsTranslucent">true</item>
    </style>

    <!--全屏-->
    <style name="FullScreenTheme" parent="AppTheme">
        <item name="android:windowFullscreen">true</item>
        <item name="windowNoTitle">true</item>

记得修改 AndroidManifest.xml中

 <activity
            android:name=".ui.activity.XXXActivity"
            android:theme="@style/AppTheme.NoActionBarAndTitle" />

相关文章

网友评论

      本文标题:Android 中启动页黑屏及白屏的解决方式

      本文链接:https://www.haomeiwen.com/subject/bjeefxtx.html