Android 启动页消除白屏

一、背景

在做启动页的时候如果把启动图片放在activity中,在低端的设备上会出现白屏或者黑屏的情况,为了消除白屏我们需要在app启动的过程中设置一张默认图片来避免白屏的情况。

二、实现方案

1、设置AndroidManifest,配置application 主题,和Activity主题

<application
    android:name=".Application"
    android:allowBackup="true"
    android:icon="@mipmap/ic_launcher"
    android:label="@string/app_name"
    android:supportsRtl="true"
    android:screenOrientation="portrait"
    android:theme="@style/NoTitleFullscreen2">
 
    <activity
        android:name=".MainActivity"
        android:screenOrientation="portrait"
        android:launchMode="singleTask"
        android:configChanges="orientation|keyboardHidden|screenSize"
        android:label="@string/app_name"
        android:theme="@style/NoTitleFullscreen2">
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />
            <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>
    </activity>
</application>

2、编辑使用到的主题:
路径为:res/values/styles.xml
其中bg_splash是一张全屏的启动图片,在这里设置的图片,在点击app图标的那一刻就会加载。因此去掉白屏或黑屏,原理:这个图片替换了相当于原来白屏或黑屏的位置

 <!--设置-全屏-->
 <style name="NoTitleFullscreen2" parent="android:Theme.DeviceDefault.Light">
     <item name="android:windowNoTitle">true</item>
     <item name="windowActionBar">false</item>
     <item name="android:windowFullscreen">true</item>
     <item name="android:windowBackground">@drawable/bg_splash</item>
 </style>

版权声明:本文为weixin_42600398原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接和本声明。