android启动图

android 12之前

是在 them的 'android:windowBackground' 属性中设置

<style name="LaunchTheme" parent="@android:style/Theme.Light.NoTitleBar">
    <!-- Show a splash screen on the activity. Automatically removed when
         the Flutter engine draws its first frame -->
    <item name="android:windowBackground">@drawable/launch_background</item>
</style>

@drawable/launch_background是xml文件

<?xml version="1.0" encoding="utf-8"?>
<!-- Modify this file to customize your launch splash screen -->
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
    <item android:drawable="?android:colorBackground" />
    <!-- You can insert your own image assets here -->
    <item>
        <bitmap
            android:gravity="fill"
            android:src="@mipmap/launch_image" />
    </item>
</layer-list>

@mipmap/launch_image 放我们的背景图

android 12之后

从 Android 12 开始,SplashScreen API 可让应用通过动画启动,包括启动时的进入应用动作、显示应用图标的启动画面,以及向应用本身的过渡。SplashScreenWindow,因此涵盖 Activity。默认情况下,此系统启动画面使用应用的启动器图标元素和主题的 windowBackground(如果为单一颜色)构建而成。

自定义
them 添加以下属性

<resources>
    <style name="LaunchTheme" parent="@android:style/Theme.Light.NoTitleBar">
        <!-- Show a splash screen on the activity. Automatically removed when
             the Flutter engine draws its first frame -->
        <item name="android:windowSplashScreenBackground">@color/splashScreenBackground</item>
  <!-- @drawable/news_avd 启动画面的元素由 Android 清单文件中的 XML 资源文件定义 -->
        <item name="android:windowSplashScreenAnimatedIcon">@drawable/news_avd</item>
        <item name="android:windowSplashScreenAnimationDuration">1000</item>
<!--        <item name="android:windowSplashScreenBrandingImage">@drawable/...</item>-->
    </style>
</resources>

向后兼容
1.核心 SplashScreen 库为搭载 API 23 及更高版本的所有设备带来了 Android 12 启动画面。如需将其添加到项目中,请将以下代码段添加到 build.gradle 文件中:

dependencies {
    implementation("androidx.core:core-splashscreen:1.0.0")
}
<style name="LaunchTheme" parent="Theme.SplashScreen">
   <!-- Set the splash screen background, animated icon, and animation
   duration. -->
   <item name="windowSplashScreenBackground">@color/...</item>

   <!-- Use windowSplashScreenAnimatedIcon to add a drawable or an animated
        drawable. One of these is required. -->
   <item name="windowSplashScreenAnimatedIcon">@drawable/...</item>
   <!-- Required for animated icons. -->
   <item name="windowSplashScreenAnimationDuration">200</item>

   <!-- Set the theme of the Activity that directly follows your splash
   screen. This is required. -->
   <item name="postSplashScreenTheme">@style/Theme.App</item>
</style>
最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容