You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Android多版本兼容:如何在Splash Screen底部添加额外图标

Android全版本启动页:居中App图标+底部额外Logo实现方案

Android 12及以上版本(API 31+)

基于系统原生SplashScreen API实现,支持自定义叠加内容,适配系统启动页动画逻辑。

1. 配置启动页主题

在res/values/styles.xml中定义继承自Theme.SplashScreen的主题:

<style name="Theme.App.Splash" parent="Theme.SplashScreen">
    <!-- 启动页背景色 -->
    <item name="android:windowBackground">@color/splash_background</item>
    <!-- 设置居中显示的App核心图标 -->
    <item name="windowSplashScreenAnimatedIcon">@drawable/ic_app_center_icon</item>
    <!-- 关闭图标默认缩放动画(按需开启) -->
    <item name="windowSplashScreenIconAnimationEnabled">false</item>
    <!-- 指定自定义内容布局,用于放置底部额外Logo -->
    <item name="windowSplashScreenContentLayout">@layout/splash_custom_content</item>
</style>

2. 创建底部Logo的自定义布局

新建res/layout/splash_custom_content.xml,通过FrameLayout实现底部居中的Logo:

<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:gravity="bottom|center_horizontal"
    android:paddingBottom="32dp">

    <!-- 底部额外Logo -->
    <ImageView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:src="@drawable/ic_bottom_logo" />

</FrameLayout>

3. 启动Activity中切换主题

在启动Activity的onCreate方法中,先初始化SplashScreen,再切换到应用主主题:

@Override
protected void onCreate(Bundle savedInstanceState) {
    // 初始化系统SplashScreen
    SplashScreen splashScreen = SplashScreen.installSplashScreen(this);
    // 可选:设置启动页保持显示的条件(比如等待数据加载完成)
    // splashScreen.setKeepOnScreenCondition(() -> isDataLoading);

    super.onCreate(savedInstanceState);
    // 切换到应用主主题
    setTheme(R.style.Theme.App.Main);
    setContentView(R.layout.activity_main);
}

4. 添加依赖库

在Module级别的build.gradle中引入SplashScreen支持库:

dependencies {
    implementation 'androidx.core:core-splashscreen:1.0.1'
}

Android 11及以下版本(API 30-)

采用传统windowBackground方式,通过LayerList层级组合背景、居中图标和底部Logo。

1. 定义传统启动页主题

在res/values/styles.xml中定义无ActionBar的主题:

<style name="Theme.App.Splash.Legacy" parent="Theme.AppCompat.NoActionBar">
    <item name="android:windowBackground">@drawable/splash_legacy_background</item>
    <item name="android:windowFullscreen">true</item>
</style>

2. 创建LayerList背景布局

新建res/drawable/splash_legacy_background.xml,按层级组合元素:

<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
    <!-- 最底层:启动页背景色 -->
    <item android:drawable="@color/splash_background" />

    <!-- 中间层:居中显示的App图标 -->
    <item>
        <bitmap
            android:gravity="center"
            android:src="@drawable/ic_app_center_icon" />
    </item>

    <!-- 最上层:底部居中的额外Logo -->
    <item>
        <bitmap
            android:gravity="bottom|center_horizontal"
            android:src="@drawable/ic_bottom_logo"
            android:paddingBottom="32dp" />
    </item>
</layer-list>

3. 启动Activity配置

创建空的启动Activity,直接跳转主页面(无需设置setContentView):

public class LegacySplashActivity extends AppCompatActivity {
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        // 跳转主Activity并关闭当前页
        startActivity(new Intent(this, MainActivity.class));
        finish();
    }
}

通用注意事项

  • 图标资源需适配不同分辨率(提供mdpi、hdpi、xhdpi等多尺寸资源),避免拉伸变形
  • 12+版本的自定义内容布局会自动跟随系统启动页的退出动画,无需额外处理
  • 低版本的LayerList需注意元素顺序,背景层必须放在最上方的item之前

内容的提问来源于stack exchange,提问作者sejn

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.06.22 08:57:40