SplashScreen的使用 - SheTieJun/BaseKit GitHub Wiki
- 使用
windowSplashScreenBackground
以特定的单色填充背景 - 使用
windowSplashScreenAnimatedIcon
替换起始窗口中心的图标。如果对象通过AnimationDrawable
和AnimatedVectorDrawable
可呈现动画效果且可绘制,则也会在显示起始窗口的同时播放动画。 - 使用
windowSplashScreenAnimationDuration
设置启动画面在关闭之前显示的时长。最长时间为 1000 毫秒。 - 使用
windowSplashScreenIconBackground
设置启动画面图标后面的背景。当窗口背景与图标之间的对比度不够高时,这很有用。 - 使用
windowSplashScreenBrandingImage
设置要显示在启动画面底部的图片。设计准则建议不要使用品牌图片。
注意上面提到的windowSplashScreenIconBackground和windowSplashScreenBrandingImage没有,这是与Android12的不同之一。
中心图标: 图标内容区域内边距2/3,防止元素被切 品牌名图标: 设计的尺寸比例为:2.5:1
<style name="Theme.Samplescompose" parent="Theme.SplashScreen.IconBackground">
<item name="windowSplashScreenAnimatedIcon">@mipmap/icon_jetpack_compose</item>
<item name="windowSplashScreenBackground">@color/white</item>
<item name="windowSplashScreenAnimationDuration">500</item>
<!-- API 31+ specific attributes -->
<item name="android:windowSplashScreenBrandingImage">@drawable/branding</item>
<!-- must be set,设置自己的主题,否则会出现状态栏异常显示的问题,如果你是只有一个界面的话-->
<item name="postSplashScreenTheme">@style/BaseTheme.MD3</item>
</style>
class MainActivity : BaseBindingActivity<MainPresenter, ActivityMainBinding>() {
private var splashScreen: SplashScreen? =null
private var isKeep = true
override fun onCreate(savedInstanceState: Bundle?) {
splashScreen = installSplashScreen()
lifecycleScope.launch {
delay(1000)
isKeep = false
}
splashScreen!!.setKeepOnScreenCondition(SplashScreen.KeepOnScreenCondition {
//指定保持启动画面展示的条件
return@KeepOnScreenCondition isKeep
})
splashScreen!!.setOnExitAnimationListener { splashScreenViewProvider ->
val splashScreenView = splashScreenViewProvider.view
val slideUp = ObjectAnimator.ofFloat(
splashScreenView,
View.ALPHA,
1f,
0f,
)
slideUp.duration = 800
slideUp.doOnEnd {
splashScreenViewProvider.remove()
}
slideUp.start()
}
super.onCreate(savedInstanceState)
}
}
-
图片选择,套了多层的图片,可能会有其他问题,动画除外
-
branding 案例:
<?xml version="1.0" encoding="utf-8"?>
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="180dp"
android:height="64dp"
android:viewportWidth="180"
android:viewportHeight="64">
<path
android:fillColor="#21223A"
android:pathData="M29.68 21.52h3.93v6.45l-0.24 2.1h0.24c0.36-0.62 0.92-1.15 1.68-1.59c0.76-0.44 1.7-0.66 2.82-0.66c0.94 0 1.83 0.2 2.67 0.6c0.86 0.38 1.61 0.92 2.25 1.62c0.66 0.68 1.18 1.5 1.56 2.46c0.38 0.96 0.57 2.01 0.57 3.15c0 1.14-0.19 2.19-0.57 3.15c-0.38 0.96-0.9 1.79-1.56 2.49c-0.64 0.68-1.39 1.22-2.25 1.62c-0.84 0.38-1.73 0.57-2.67 0.57c-1.12 0-2.06-0.22-2.82-0.66c-0.76-0.44-1.32-0.97-1.68-1.59h-0.24V43h-3.69V21.52zm7.62 18.33c0.52 0 1.01-0.1 1.47-0.3c0.48-0.2 0.9-0.48 1.26-0.84s0.65-0.8 0.87-1.32c0.22-0.52 0.33-1.1 0.33-1.74c0-0.64-0.11-1.22-0.33-1.74c-0.22-0.52-0.51-0.96-0.87-1.32c-0.36-0.36-0.78-0.64-1.26-0.84c-0.46-0.2-0.95-0.3-1.47-0.3s-1.02 0.1-1.5 0.3c-0.46 0.18-0.87 0.45-1.23 0.81c-0.36 0.36-0.65 0.8-0.87 1.32c-0.22 0.52-0.33 1.11-0.33 1.77c0 0.66 0.11 1.25 0.33 1.77c0.22 0.52 0.51 0.96 0.87 1.32c0.36 0.36 0.77 0.64 1.23 0.84c0.48 0.18 0.98 0.27 1.5 0.27zM47.38 28.3h3.69v2.04h0.24c0.18-0.36 0.42-0.69 0.72-0.99c0.3-0.3 0.63-0.56 0.99-0.78c0.38-0.22 0.78-0.39 1.2-0.51c0.44-0.12 0.87-0.18 1.29-0.18c0.52 0 0.96 0.05 1.32 0.15c0.38 0.1 0.7 0.23 0.96 0.39l-1.05 3.57c-0.24-0.12-0.51-0.21-0.81-0.27c-0.28-0.08-0.63-0.12-1.05-0.12c-0.54 0-1.03 0.11-1.47 0.33c-0.44 0.2-0.82 0.49-1.14 0.87c-0.3 0.38-0.54 0.83-0.72 1.35c-0.16 0.5-0.24 1.05-0.24 1.65V43h-3.93V28.3zm20.69 13.14h-0.24c-0.46 0.56-1.02 1.04-1.68 1.44c-0.64 0.4-1.47 0.6-2.5 0.6c-0.75 0-1.47-0.13-2.15-0.39c-0.66-0.24-1.24-0.58-1.74-1.02c-0.5-0.44-0.9-0.97-1.17-1.59c-0.28-0.62-0.42-1.3-0.42-2.04c0-0.76 0.15-1.44 0.45-2.04c0.3-0.62 0.72-1.15 1.26-1.59c0.54-0.44 1.17-0.77 1.89-0.99c0.74-0.24 1.54-0.36 2.4-0.36c0.96 0 1.75 0.08 2.37 0.24c0.62 0.14 1.13 0.29 1.53 0.45V33.7c0-0.78-0.31-1.42-0.93-1.92c-0.62-0.52-1.4-0.78-2.31-0.78c-1.36 0-2.51 0.57-3.45 1.71l-2.85-1.95c1.56-1.96 3.69-2.94 6.39-2.94c2.28 0 4.02 0.54 5.22 1.62c1.2 1.06 1.8 2.64 1.8 4.74V43h-3.87v-1.56zm0-4.41c-0.46-0.22-0.94-0.39-1.44-0.51c-0.48-0.14-1.01-0.21-1.6-0.21c-0.93 0-1.66 0.21-2.18 0.63c-0.5 0.4-0.75 0.9-0.75 1.5s0.24 1.08 0.72 1.44c0.5 0.36 1.07 0.54 1.7 0.54c0.53 0 1-0.09 1.45-0.27c0.44-0.2 0.8-0.45 1.1-0.75c0.33-0.32 0.57-0.68 0.73-1.08c0.18-0.42 0.27-0.85 0.27-1.29zm10.68-6.81H79c0.46-0.74 1.08-1.32 1.86-1.74c0.78-0.44 1.67-0.66 2.67-0.66c0.92 0 1.73 0.15 2.43 0.45c0.7 0.3 1.27 0.73 1.71 1.29c0.46 0.54 0.8 1.2 1.02 1.98c0.24 0.76 0.36 1.61 0.36 2.55V43h-3.93v-8.43c0-1.06-0.24-1.84-0.72-2.34c-0.46-0.52-1.14-0.78-2.04-0.78c-0.54 0-1.02 0.12-1.44 0.36c-0.4 0.22-0.75 0.53-1.05 0.93c-0.28 0.38-0.5 0.84-0.66 1.38c-0.14 0.52-0.2 1.08-0.2 1.68V43h-3.94V28.3h3.7v1.92zm24.49 11.01H103c-0.36 0.62-0.92 1.15-1.68 1.59c-0.76 0.44-1.7 0.66-2.82 0.66c-0.94 0-1.84-0.19-2.7-0.57c-0.84-0.4-1.6-0.94-2.25-1.62c-0.64-0.7-1.15-1.53-1.53-2.49c-0.38-0.96-0.57-2.01-0.57-3.15c0-1.14 0.19-2.19 0.57-3.15c0.38-0.96 0.89-1.78 1.53-2.46c0.66-0.7 1.4-1.24 2.25-1.62c0.86-0.4 1.76-0.6 2.7-0.6c1.12 0 2.06 0.22 2.82 0.66c0.76 0.44 1.32 0.97 1.68 1.59h0.24l-0.24-2.1v-6.45h3.93V43h-3.7v-1.77zm-3.93-1.38c0.52 0 1-0.09 1.47-0.27c0.48-0.2 0.9-0.48 1.26-0.84s0.65-0.8 0.87-1.32c0.22-0.52 0.33-1.11 0.33-1.77c0-0.66-0.11-1.25-0.33-1.77c-0.22-0.52-0.51-0.96-0.87-1.32c-0.36-0.36-0.78-0.63-1.26-0.81c-0.46-0.2-0.95-0.3-1.47-0.3s-1.02 0.1-1.5 0.3c-0.46 0.2-0.87 0.48-1.23 0.84s-0.65 0.8-0.87 1.32c-0.22 0.52-0.33 1.1-0.33 1.74c0 0.64 0.1 1.22 0.33 1.74c0.22 0.52 0.5 0.96 0.87 1.32c0.36 0.36 0.77 0.64 1.23 0.84c0.48 0.2 0.98 0.3 1.5 0.3zm13.16-13.68c-0.34 0-0.67-0.06-1-0.18c-0.3-0.14-0.56-0.32-0.8-0.54c-0.22-0.24-0.4-0.51-0.54-0.81c-0.12-0.3-0.18-0.63-0.18-0.99s0.06-0.69 0.18-0.99c0.14-0.3 0.32-0.56 0.54-0.78c0.24-0.24 0.5-0.42 0.8-0.54c0.33-0.14 0.66-0.21 1-0.21c0.7 0 1.3 0.25 1.8 0.75c0.5 0.48 0.75 1.07 0.75 1.77s-0.25 1.3-0.75 1.8c-0.5 0.48-1.1 0.72-1.8 0.72zM110.52 43V28.3h3.93V43h-3.93zm11.2-12.78h0.25c0.46-0.74 1.08-1.32 1.86-1.74c0.78-0.44 1.67-0.66 2.67-0.66c0.92 0 1.73 0.15 2.43 0.45c0.7 0.3 1.27 0.73 1.7 1.29c0.47 0.54 0.8 1.2 1.03 1.98c0.24 0.76 0.36 1.61 0.36 2.55V43h-3.93v-8.43c0-1.06-0.24-1.84-0.72-2.34c-0.46-0.52-1.14-0.78-2.04-0.78c-0.54 0-1.02 0.12-1.44 0.36c-0.4 0.22-0.75 0.53-1.05 0.93c-0.28 0.38-0.5 0.84-0.66 1.38c-0.14 0.52-0.21 1.08-0.21 1.68V43h-3.93V28.3h3.69v1.92zm20.18 19.74c-1.04 0-1.97-0.14-2.8-0.42c-0.8-0.26-1.5-0.61-2.1-1.05c-0.6-0.42-1.1-0.89-1.5-1.41c-0.4-0.52-0.68-1.04-0.86-1.56l3.75-1.5c0.28 0.78 0.74 1.38 1.38 1.8c0.64 0.44 1.35 0.66 2.13 0.66c1.24 0 2.22-0.39 2.94-1.17c0.72-0.76 1.08-1.83 1.08-3.21v-1.02h-0.24c-0.46 0.64-1.07 1.15-1.83 1.53c-0.74 0.36-1.62 0.54-2.64 0.54c-0.88 0-1.74-0.18-2.58-0.54c-0.82-0.36-1.55-0.87-2.2-1.53c-0.63-0.68-1.15-1.49-1.55-2.43c-0.4-0.94-0.6-1.99-0.6-3.15s0.2-2.21 0.6-3.15c0.4-0.96 0.92-1.77 1.56-2.43c0.64-0.68 1.37-1.2 2.19-1.56c0.84-0.36 1.7-0.54 2.58-0.54c1.02 0 1.9 0.19 2.64 0.57c0.76 0.36 1.37 0.86 1.83 1.5h0.24V28.3h3.75v13.65c0 1.24-0.2 2.35-0.57 3.33c-0.38 1-0.91 1.84-1.6 2.52c-0.67 0.7-1.5 1.23-2.45 1.59c-0.94 0.38-2 0.57-3.15 0.57zm0.15-10.35c0.48 0 0.95-0.09 1.4-0.27c0.49-0.18 0.9-0.44 1.27-0.78c0.36-0.36 0.65-0.79 0.87-1.29c0.22-0.52 0.33-1.11 0.33-1.77c0-0.66-0.11-1.25-0.33-1.77c-0.22-0.52-0.51-0.95-0.87-1.29c-0.36-0.36-0.78-0.63-1.26-0.81c-0.46-0.18-0.93-0.27-1.41-0.27c-0.48 0-0.95 0.09-1.41 0.27c-0.46 0.18-0.87 0.45-1.23 0.81c-0.36 0.36-0.65 0.8-0.87 1.32c-0.22 0.5-0.33 1.08-0.33 1.74c0 0.66 0.1 1.25 0.33 1.77c0.22 0.5 0.5 0.93 0.87 1.29c0.36 0.34 0.77 0.6 1.23 0.78c0.46 0.18 0.93 0.27 1.4 0.27z"/>
</vector>
- You need to use a Theme.AppCompat theme (or descendant) with this activity.
必须使用
Theme.AppCompat
<item name="postSplashScreenTheme">@style/Theme.MaterialComponents.DayNight.DarkActionBar</item>