SplashScreen使用

从 Android 12 开始,SplashScreen API 可让应用通过动画启动,包括启动时的进入应用动作、显示应用图标的启动画面,以及向应用本身的过渡。SplashScreen 是 Window,因此涵盖 Activity官方文档

相关属性

  1. windowSplashScreenBackground属性单色填充背景
xml 复制代码
<item name="android:windowSplashScreenBackground">@android:color/holo_orange_light</item>
  1. windowSplashScreenAnimatedIcon 替换默认的窗口中心的启动画面图标。如果该对象可通过 AnimationDrawableAnimatedVectorDrawable呈现动画效果和进行绘制,还需要设置 windowSplashScreenAnimationDuration以在显示起始窗口的同时播放动画。
xml 复制代码
<item name="android:windowSplashScreenAnimatedIcon">@drawable/logo</item>
  1. windowSplashScreenAnimationDuration指定启动画面图标动画的时长。设置后对实际启动画面的显示时间不会有影响,可以在自定义启动画面退出动画时使用 SplashScreenView#getIconAnimationDuration检索图标动画的时长,单位为ms。让启动画面显示更长时间
xml 复制代码
<item name="android:windowSplashScreenAnimationDuration">500</item>
  1. windowSplashScreenIconBackgroundColor设置启动画面图标后面的背景。当窗口背景与图标之间的颜色对比度不够高时,起到颜色过渡的作用。
xml 复制代码
<item name="android:windowSplashScreenIconBackgroundColor">@android:color/holo_purple</item>
  1. windowSplashScreenBrandingImage设置要显示在启动画面底部的品牌logo图片。但是Google不建议使用
xml 复制代码
<item name="android:windowSplashScreenBrandingImage">@drawable/logo_icon</item>

以下有两种方式调整SplashScreen

一、禁止使用SplashScreen

位置:android/app/src/main/res/values-v31/styles.xml

通过AndroidManifest.xml 内的android:theme="@style/LaunchTheme" 找到使用的主题名称为LaunchTheme ,找到v31/style.xml 修改为如下

xml 复制代码
<style name="LaunchTheme" parent="Theme.AppCompat.Light.NoActionBar">
    <!-- 不显示SplashScreen -->
    <item name="android:windowNoTitle">true</item>
    <item name="android:windowBackground">@android:color/transparent</item>
    <item name="android:windowIsTranslucent">true</item>
    <item name="android:screenOrientation">portrait</item>
    <item name="android:statusBarColor">@android:color/transparent</item>
</style>

二、修改

颜色资源文件位置

位置:android/app/src/main/res/values/colors.xml

xml 复制代码
<?xml version="1.0" encoding="utf-8"?>
<resources>
    <color name="red">#ff0000</color>
    <color name="splash_screen_background">#7B5AB6</color>
</resources>

修改位置同上

xml 复制代码
<style name="LaunchTheme" parent="Theme.AppCompat.Light.NoActionBar">
    <!-- Show a splash screen on the activity. Automatically removed when
         Flutter draws its first frame -->
    <item name="android:windowSplashScreenBackground">@color/splash_screen_background</item>
    <item name="android:windowSplashScreenIconBackgroundColor">@color/red</item>
    <item name="android:windowSplashScreenAnimatedIcon">@drawable/news_avd_v02</item>
    <item name="android:windowSplashScreenAnimationDuration">500</item>
    <item name="android:windowSplashScreenBrandingImage">@drawable/news_avd_v02</item>
</style>
  1. 如果windowSplashScreenAnimatedIcon 非透明背景,且不是圆形,则会被裁剪成圆,此时windowSplashScreenIconBackgroundColor 不显示
  2. 如果windowSplashScreenAnimatedIcon 为动效,但是未设置windowSplashScreenAnimationDuration ,则展示静止
相关推荐
uwvwko7 小时前
BUUCTF——web刷题第一页题解
android·前端·数据库·php·web·ctf
fzxwl7 小时前
隆重推荐(Android 和 iOS)UI 自动化工具—Maestro
android·ui·ios
LittleLoveBoy10 小时前
踩坑:uiautomatorviewer.bat 打不开
android
居然是阿宋10 小时前
Android核心系统服务:AMS、WMS、PMS 与 system_server 进程解析
android
CGG9213 小时前
【单例模式】
android·java·单例模式
kp0000013 小时前
PHP弱类型安全漏洞解析与防范指南
android·开发语言·安全·web安全·php·漏洞
编程乐学(Arfan开发工程师)18 小时前
06、基础入门-SpringBoot-依赖管理特性
android·spring boot·后端
androidwork19 小时前
使用 Kotlin 和 Jetpack Compose 开发 Wear OS 应用的完整指南
android·kotlin
繁依Fanyi20 小时前
Animaster:一次由 CodeBuddy 主导的 CSS 动画编辑器诞生记
android·前端·css·编辑器·codebuddy首席试玩官
想起你的日子20 小时前
Android studio 实现弹出表单编辑界面
java·前端·android studio