SplashActivity的实现

SplashActivity的实现步骤

由于在APP启动页面加载时,会有白屏闪过,用这种方法加载启动页面的图片会避免此问题,达到秒开的效果。

1 在drawable文件夹下建立splash.xml.
<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
    <item
        android:drawable="@color/dark_gray"></item>
    <item>
        <bitmap android:src="@mipmap/loading"
            android:gravity="center"/>
    </item>
</layer-list>
2 在样式文件style.xml中为SplashActivity建立一个theme.
<resources>

    <!-- Base application theme. -->
    <style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
    </style>

    <style name="SplashTheme" parent="Theme.AppCompat.NoActionBar">
        <item name="android:windowBackground">@drawable/splash</item>
    </style>

</resources>
3 在AndroidManifest.xml中定义SplashActivity的theme为splash_theme.
<activity android:name=".SplashActivity"
          android:theme="@style/SplashTheme">
       <intent-filter>
          <action android:name="android.intent.action.MAIN"/>
          <category android:name="android.intent.category.LAUNCHER"/>
       </intent-filter>
</activity>
4 为了保证启动速度,SplashActivity不需要实现setContentView()方法。

如果你的SplashActivity设置了layout文件,那么其在app完全初始化完成后才会显示,带来一定的耗时。这里直接以theme作为SplashActivity展示的UI,减少了加载时间,能达到秒开的效果。使用该启动方式亦可以避免有些app点开时出现的白屏问题。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值