0
点赞
收藏
分享

微信扫一扫

Android APP 应用启动页白屏优化

1. 甩锅给系统

使用透明主题:

<item name="android:windowIsTranslucent">true</item>

Activity.onCreate() 之前 App 不做显示,这样用户误以为是手机慢了,这种瞒天过海的方案大家还是不要用了。

<resources>

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

</resources>

2.主题替换

我们在style中自定义一个样式Lancher,在其中放一张背景图片,或是广告图片之类的。

    <style name="AppTheme.Launcher" parent="AppTheme">
<!--<item name="android:windowBackground">@color/startingwindow_bgcolor</item>-->
        <item name="android:windowBackground">@drawable/bg</item>
    </style>

把这个样式设置给启动的 Activity

            <activity
            android:name=".activity.SplashActivity"
            android:screenOrientation="portrait"
            android:theme="@style/AppTheme.Launcher"
            >

然后在 Activity 的 onCreate 方法,把 Activity 设置回原来的主题

@Override
    protected void onCreate(Bundle savedInstanceState) {
        //替换为原来的主题,在onCreate之前调用
        setTheme(R.style.AppTheme);
        super.onCreate(savedInstanceState);
    }
举报

相关推荐

0 条评论