一、添加启动页的 Theme
<style name="AppTheme.Base" parent="Theme.AppCompat.Light.NoActionBar" />
<style name="AppTheme.Splash" parent="AppTheme.Base">
<item name="android:windowTranslucentNavigation">true</item>
<item name="android:windowTranslucentStatus">true</item>
<item name="statusBarBackground">@color/transparent</item>
<item name="android:windowNoTitle">true</item>
<item name="android:windowBackground">@drawable/lay_splash</item>
</style>
使用 layer-list 作为背景图,防止 StartingWindow 拉伸图片。
注意:这里的背景图片如果是全屏的,要根据尺寸放对文件夹,不然会出现图片过大,过小等问题
<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
<item android:drawable="@color/white" />
<item>
<bitmap
android:gravity="center"
android:src="@mipmap/ic_launcher" />
</item>
</layer-list>
应用到启动页
<activity
android:name=".SplashActivity"
android:exported="true"
android:theme="@style/AppTheme.Splash">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
二、将启动页的背景设置为透明
适用于不做UI变化,直接进入到主页面的APP,从 StartingWindow 到进入主页面这段时间有很好的过度。
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@color/transparent">
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="这是启动页"
app:layout_constraintTop_toTopOf="parent" />
</androidx.constraintlayout.widget.ConstraintLayout>
本文详细介绍如何在Android应用中优化启动页体验,包括添加启动页Theme,设置透明背景,使用layer-list防止图片拉伸,以及如何将这些应用到启动页Activity中。
4496

被折叠的 条评论
为什么被折叠?



