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

如何实现底部带文字的启动页?Splash Screen API可行性咨询

问题解答

能否通过Splash Screen API实现该效果?

可以实现。Android 12及以上的Splash Screen API原生支持这种居中图标+底部文字的启动页样式,具体实现步骤如下:

  • 配置居中图标:默认情况下API会将启动图标居中显示,只需在主题中继承Theme.SplashScreen并指定图标资源:

    <style name="AppTheme.Splash" parent="Theme.SplashScreen">
        <item name="windowSplashScreenAnimatedIcon">@drawable/ic_app_logo</item>
        <item name="postSplashScreenTheme">@style/AppTheme</item>
    </style>
    

    将该主题设置给启动Activity即可。

  • 添加底部文字:API提供windowSplashScreenBrandingImage属性,可将包含文字的Drawable(比如把文字做成矢量图或静态图片)设置为底部标识,默认会显示在启动页底部。若需要调整位置或动态修改,可通过代码监听启动页退出动画时修改布局:

    class MainActivity : AppCompatActivity() {
        override fun onCreate(savedInstanceState: Bundle?) {
            super.onCreate(savedInstanceState)
            val splashScreen = installSplashScreen()
            
            // 自定义底部文字(Branding Image)位置
            splashScreen.setOnExitAnimationListener { view ->
                val brandingView = view.view.findViewById<ImageView>(com.google.android.material.R.id.splashscreen_branding_image)
                brandingView?.apply {
                    val params = layoutParams as ConstraintLayout.LayoutParams
                    params.bottomMargin = convertDpToPx(32)
                    layoutParams = params
                }
                
                // 执行退出动画
                view.animate()
                    .alpha(0f)
                    .withEndAction { view.remove() }
                    .start()
            }
            
            setContentView(R.layout.activity_main)
        }
        
        private fun convertDpToPx(dp: Int): Int {
            return (dp * resources.displayMetrics.density).toInt()
        }
    }
    

自定义启动页替代方案(兼容低版本/复杂需求)

如果需要兼容Android 11及以下版本,或者要实现动态修改文字等更灵活的需求,推荐以下原生自定义方案:

  • 独立启动页Activity:创建一个专门的启动页Activity,直接在布局中定义居中图标和底部文字,完成初始化后跳转到主页面:

    <!-- res/layout/activity_splash.xml -->
    <LinearLayout
        xmlns:android="http://schemas.android.com/apk/res/android"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:gravity="center"
        android:orientation="vertical"
        android:background="@color/white">
        
        <ImageView
            android:layout_width="120dp"
            android:layout_height="120dp"
            android:src="@drawable/ic_app_logo"/>
            
        <TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_marginTop="auto"
            android:layout_marginBottom="32dp"
            android:text="Google LLC"
            android:textColor="@color/gray"/>
    </LinearLayout>
    

    代码控制跳转:

    class SplashActivity : AppCompatActivity() {
        override fun onCreate(savedInstanceState: Bundle?) {
            super.onCreate(savedInstanceState)
            setContentView(R.layout.activity_splash)
            
            // 模拟初始化逻辑,完成后跳转
            Handler(Looper.getMainLooper()).postDelayed({
                startActivity(Intent(this, MainActivity::class.java))
                finish()
            }, 1500)
        }
    }
    

    注意在AndroidManifest.xml中设置该Activity为启动页,并指定主题避免白屏问题。

  • 兼容包适配:如果想基于官方API适配低版本,可以使用androidx.core:core-splashscreen兼容库,它能让Android 11及以下设备也使用类似的启动页样式,配置逻辑与官方API基本一致。


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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.08.01 22:16:16