需求
项目启动时,需要在开屏页显示一个 Logo
处理方式:
先在 style.xml 中新建一个 样式:
<style name="AppTheme_Splash" parent="Theme.AppCompat.Light.NoActionBar">
<item name="android:windowBackground">@drawable/splash</item>
<item name="android:windowNoTitle">true</item>
<item name="android:windowFullscreen">true</item>
<item name="windowActionBar">false</item>
<item name="android:windowContentOverlay">@null</item>
</style>
注意:重点是 android:windowBackground
属性。
在 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/white" />
<item>
<!-- 这里设置开屏页需要显示的 LOGO -->
<bitmap
android:gravity="center"
android:src="@drawable/logo" />
</item>
</layer-list>
注意: 显示的Logo 尺寸要求切图时就控制好尺寸。这里是没法限制尺寸的。
使用
样式创建好之后,配置给你的 启动页面
<activity
android:name=".feature.LoadingActivity"
android:screenOrientation="portrait"
android:theme="@style/AppTheme_Splash">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
然后就是,你的 LoadingActivity 页面不需要有布局,或者只写一个根布局,然后背景颜色设置为透明。
网友评论