android app 优化启动体验, 不闪白屏并且快速展示 splash

本文首发在我的个人博客: http://www.geekqian.com/post/9d4eac9b.html

转载请注明出处

要优化 app 的启动体验, 首先在清单文件中第一个启动的 SplashActivity 使用了 theme 的方式.

<activity
        android:name="com.ingdan.xxx.ui.activity.SplashActivity"
        android:theme="@style/SplashTheme">
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />

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

在 style.xml 文件中定义

<style name="SplashTheme" parent="AppTheme">
    <item name="android:windowBackground">@drawable/splash</item>
    <item name="android:windowFullscreen">true</item>
</style>

注意 @drawable/splash 可以是一张图片, 也可以是定义在 drawable 文件夹中的一个 splash.xml 文件.

我这里使用的是 xml 文件的方式.

<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">

<item android:drawable="@color/colorWhite"/>

<item>
    <bitmap android:src="@drawable/splash_default"
        android:gravity="center"
        />
</item>
</layer-list>

当时好像是出现了一些问题才这么写. 具体啥问题我想不起来了, 反正这样没毛病.. 哈

另外接入 bugly 后发现了这里报了一个 XmlPullParserException 的问题, 查了一下应该是之前这个 layer-list 的 item 中定义了 @drawable/splash 这种方式导致的, 之前 splash 图片的名字就叫 splash , 导致跟 splash.xml 冲突. 所以改为了 splash_default就搞定了.

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值