应用启动白屏的解决办法

对于应用打开的第一个欢迎页面,一般我们会设置一个背景图片
比如:

<?xml version="1.0" encoding="utf-8"?>
<com.facebook.drawee.view.SimpleDraweeView android:id="@+id/iv_start"
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:fitsSystemWindows="true"
    android:orientation="vertical"
    app:placeholderImage="@drawable/ic_splash"
    app:actualImageScaleType="fitXY"
    app:placeholderImageScaleType="fitXY"
    style="@style/facebook_drawee_view_rect"
    xmlns:app="http://schemas.android.com/apk/res-auto">

</com.facebook.drawee.view.SimpleDraweeView>

但是应用启动的时候,总会有几秒的白屏,给用户的体验不太好。

解决方案:
1. 定义自己的theme主题

    <!-- theme 主题 -->
    <style name="MyAppCompatTheme.NoActionBar" parent="Theme.AppCompat.Light.NoActionBar">
        <item name="android:windowBackground">@null</item>
        <!--<item name="colorPrimary">@color/unsigned_color_black</item>-->
        <item name="colorPrimaryDark">#999999</item>
        <item name="colorAccent">#aaaaaa</item>
    </style>

    <style name="MyAppCompatTheme.NoActionBar.FullScreen" parent="MyAppCompatTheme.NoActionBar">
        <item name="android:windowFullscreen">true</item>
        <item name="android:windowBackground">@color/white</item>
    </style>


    <style name="MyAppCompatTheme.NoActionBar.FullScreen_Splash" parent="MyAppCompatTheme.NoActionBar.FullScreen">
        <item name="android:windowBackground">@drawable/ic_splash</item>
    </style>

2.给欢迎页设置theme

<!-- 欢迎界面 -->
        <activity
            android:name=".Activity.WelcomeActivity"
            android:screenOrientation="portrait"
            android:theme="@style/MyAppCompatTheme.NoActionBar.FullScreen_Splash"
            android:windowSoftInputMode="stateAlwaysHidden|adjustResize">
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />

                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>

3.去掉我们在欢迎页xml中的背景图

<?xml version="1.0" encoding="utf-8"?>
<com.facebook.drawee.view.SimpleDraweeView android:id="@+id/iv_start"
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:fitsSystemWindows="true"
    android:orientation="vertical"
    app:actualImageScaleType="fitXY"
    app:placeholderImageScaleType="fitXY"
    style="@style/facebook_drawee_view_rect"
    xmlns:app="http://schemas.android.com/apk/res-auto">

</com.facebook.drawee.view.SimpleDraweeView>

4.这样就可以在应用启动的瞬间加载我们的背景图片,给用户的体验也会比较好。

此外,还可以在应用中设置背景色,来达到类似今日头条广告的效果
比如(判断是否有最新的图片,如果有就在应用启动后,加载背景,实现欢迎页背景切换的效果):

        final SimpleDraweeView iv_start = (SimpleDraweeView) findViewById(R.id.iv_start);
        String siFile = Local.getSifile();
        if(!TextUtils.isEmpty(siFile)){
            Log.i(TAG, "initViews: siFile:" + siFile);
            File file = new File(siFile);
            if(file.exists()) {
                Uri uri = Uri.fromFile(file);
                if(iv_start != null)
                    iv_start.setImageURI(uri);
            }else{
                Local.updateSiVersion(-1L);
            }
        }
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值