API 31下如何隐藏启动页中间的应用图标/启动图标
解决API 31下启动屏自动显示应用图标的问题
在Android 12(API 31)及以上版本中,系统会默认在启动屏叠加显示应用的启动图标,哪怕你已经设置了自定义的windowBackground,这个图标依然会出现。以下是两种可行的解决方法:
方法一:直接修改现有主题隐藏图标
调整你当前的AppTheme.NoActionBarLaunch主题,添加API 31专属的配置项,把系统默认图标设为透明:
<style name="AppTheme.NoActionBarLaunch" parent="AppTheme.NoActionBar"> <item name="android:windowBackground">@drawable/splashscreen</item> <item name="android:windowDisablePreview">true</item> <!-- 针对API 31+隐藏系统启动图标 --> <item name="android:windowSplashScreenAnimatedIcon">@android:color/transparent</item> <item name="android:windowSplashScreenIconBackgroundColor">@android:color/transparent</item> </style>
windowSplashScreenAnimatedIcon设为透明后,系统默认的启动图标会直接消失windowSplashScreenIconBackgroundColor同步设为透明,避免图标区域留下突兀的背景色块
方法二:用官方SplashScreen API自定义启动屏(推荐)
API 31及以上官方推荐使用SplashScreen API管理启动屏,能更精准控制显示内容,步骤如下:
- 在
res/values/styles.xml中创建启动屏专属主题:
<style name="SplashTheme" parent="Theme.SplashScreen"> <!-- 设置自定义启动屏背景 --> <item name="windowSplashScreenBackground">@drawable/splashscreen</item> <!-- 隐藏系统默认图标 --> <item name="windowSplashScreenAnimatedIcon">@android:color/transparent</item> <!-- 指定启动完成后切换到的应用主题 --> <item name="postSplashScreenTheme">@style/AppTheme.NoActionBar</item> </style>
- 在
AndroidManifest.xml中把启动Activity的主题替换为这个SplashTheme:
<activity android:name=".YourLaunchActivity" android:theme="@style/SplashTheme"> <intent-filter> <action android:name="android.intent.action.MAIN" /> <category android:name="android.intent.category.LAUNCHER" /> </intent-filter> </activity>
- 在启动Activity的
onCreate方法中添加启动屏过渡处理代码:
override fun onCreate(savedInstanceState: Bundle?) { // 初始化启动屏 val splashScreen = installSplashScreen() super.onCreate(savedInstanceState) // 如果需要延迟启动屏消失(比如等待数据加载),可以添加条件判断 // splashScreen.setKeepOnScreenCondition { /* 加载完成返回false */ } setContentView(R.layout.activity_main) }
这种方式符合Android 12+的设计规范,还能避免启动时的白屏闪烁问题。
额外注意
确保你的splashscreen drawable是完整的启动屏背景,不要预留图标位置,否则可能出现显示错位。
内容的提问来源于stack exchange,提问作者Abhijit Chakra
相关产品推荐
相关产品推荐

