背景:
每个app都一个启动页,
作用:
它的作用是app的宣传页,一般是一句sologen和图标组合。对于程序员来说,它可以做些初始化以及让Application足够时间初始化第三方SDK
效果图:
![](https://img.haomeiwen.com/i8703441/4d14155944e201ab.jpg)
思路:
不能直接写在Activity的xml里面,这样会有启动时的闪白,就很突兀。
我们通过给Activity的theme,设置在background里面
关键代码:
首先建好背景的drawable
start_app_bg.xml
<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
<item>
<shape>
<solid android:color="@color/white"/>
</shape>
</item>
<item>
<bitmap android:src="@mipmap/start_btm_bg"
android:gravity="center_horizontal|bottom"
/>
</item>
<item
android:top="@dimen/d200px">
<bitmap android:src="@mipmap/start_logo"
android:gravity="center_horizontal|top"/>
</item>
</layer-list>
引用的theme
<style name="AppThemeGuide" parent="AppTheme">
<!-- Customize your theme here. -->
<!--<item name="android:windowBackground">@mipmap/ic_start_default_bg</item>-->
<item name="android:windowBackground">@drawable/start_app_bg</item>
<!-- Customize your theme here. -->
<item name="android:windowFullscreen">true</item>
</style>
<style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
<!-- Customize your theme here. -->
<item name="windowNoTitle">true</item>
<item name="colorPrimary">@color/c_main</item>
<item name="colorPrimaryDark">@color/colorPrimaryDark</item>
<item name="colorAccent">@color/c_main</item>
</style>
具体使用位置,假设StartupActivity是启动页
<activity
android:name=".modules.loginregist.activity.StartupActivity"
android:configChanges="orientation|keyboardHidden|keyboard|screenSize"
android:screenOrientation="portrait"
android:theme="@style/AppThemeGuide">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
网友评论