Android app启动闪屏主题设置

以农行掌上银行为例我们来谈谈应用启动后闪白屏,若干秒之后进入Splash界面(欢迎页面)的问题。

其实这种问题不只是农行APP的专利,其它很多APP都有这种问题,默认不对SplashActivity(启动应用的Activity)的主题背景做处理都是白色的,除非为application的主题设置了背景色。可是有很多APP它们启动之后从来没有闪过一下白屏(肉眼分辨不出有闪白屏):


支付宝和网易有道词典很明显没有闪出白屏的问题,给人的感觉是点击应用图标之后,应用马上响应、加载闪屏logo进入应用主界面。

如何让我们的应用和支付宝、网易有道词典一样点击之后就马上响应呢?

其实很简单:

<application
        android:allowBackup="true"
        android:icon="@mipmap/logo"
        android:label="@string/app_name"
        android:supportsRtl="true"
        android:theme="@style/AppTheme">
        <activity
            android:name=".SplashActivity"
            android:theme="@style/launch_theme">
            <intent-filter>
                <action android:name="android.intent.action.MAIN"/>

                <category android:name="android.intent.category.LAUNCHER"/>
            </intent-filter>
        </activity>
        <activity android:name=".MainActivity">
        </activity>
 </application>
我们为启动应用的SplashActivity添加一个theme主题,launch_theme:
<style name="launch_theme" parent="Theme.AppCompat.Light.NoActionBar">
        <item name="windowNoTitle">true</item>
        <item name="android:windowFullscreen">true</item>
        <item name="android:windowBackground">@drawable/launch_bg</item>
</style>
重点就在于windowBackground属性,launch_bg.xml
<?xml version="1.0" encoding="utf-8"?>

<layer-list xmlns:android="http://schemas.android.com/apk/res/android"
            android:opacity="opaque">
    <item>
        <shape android:shape="rectangle">
            <solid android:color="@color/colorFFFFFF"/>
        </shape>
    </item>
    <item>
        <bitmap
            android:gravity="center|bottom"
            android:src="@drawable/splash_pic"/>
    </item>
</layer-list>
splash_pic.png闪屏图标如下图:

SplashActivity对应的布局文件activity_splash.xml

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/activity_splash"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="@color/colorFFFFFF">

    <ImageView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentBottom="true"
        android:layout_centerHorizontal="true"
        android:src="@drawable/splash_pic"/>
</RelativeLayout>

activity_splash.xml页面效果与launch_bg.xml页面效果一模一样,用户点击应用图标后看到的是我们设置的两个相同的页面(感觉是一个页面),之后进入主页面。

如此设置之后,我们来看看启动效果图:


处理应用启动后白屏的问题核心是修改启动应用的Activity的theme属性,各应用可以根据自身应用的风格样式设计修改,给用户的感觉舒服自然就好。

  • 1
    点赞
  • 9
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值