Android应用横屏模式下启动页后摄像头下方状态栏变白求助
解决Android横屏模式下启动页结束后状态栏变白的问题
问题背景
集成androidx.core:core-splashscreen:1.0.0启动页组件后,横屏模式下启动页结束时,摄像头下方的状态栏从启动页期间的黑色变为白色,需要修复该状态不一致问题。当前启动页主题配置如下:
<resources> <style name="Theme.Zebraman.Starting" parent="Theme.SplashScreen"> <item name="windowSplashScreenBackground">@color/darkThemeTopBar</item> <item name="windowSplashScreenAnimatedIcon">@mipmap/ic_splash_dark_round</item> <item name="postSplashScreenTheme">@style/Theme.Zebraman</item> </style> </resources>
解决方案
1. 完善启动页主题的状态栏配置
在启动页主题中显式添加状态栏颜色和文字适配属性,保证启动页期间与后续页面的状态栏状态一致:
<resources> <style name="Theme.Zebraman.Starting" parent="Theme.SplashScreen"> <item name="windowSplashScreenBackground">@color/darkThemeTopBar</item> <item name="windowSplashScreenAnimatedIcon">@mipmap/ic_splash_dark_round</item> <item name="postSplashScreenTheme">@style/Theme.Zebraman</item> <!-- 添加以下状态栏配置 --> <item name="android:statusBarColor">@color/darkThemeTopBar</item> <!-- 若状态栏文字为浅色,设置为false;若为深色则设为true --> <item name="android:windowLightStatusBar">false</item> </style> </resources>
2. 检查目标主题(Theme.Zebraman)的横屏配置
确保Theme.Zebraman在横屏模式下的状态栏颜色正确:
- 若项目存在
values-land资源文件夹,检查其中的主题配置,确认android:statusBarColor和android:windowLightStatusBar属性与启动页主题一致; - 若没有单独的横屏主题,直接在
values/styles.xml的Theme.Zebraman中添加上述状态栏属性,保证横竖屏状态统一。
3. 代码层面强制设置状态栏(备选方案)
如果上述主题配置无效,可在Activity的onCreate方法中,完成启动页初始化后手动设置状态栏:
override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) // 初始化启动页 installSplashScreen() setContentView(R.layout.activity_main) // 强制设置状态栏颜色和文字样式 window.statusBarColor = ContextCompat.getColor(this, R.color.darkThemeTopBar) WindowInsetsControllerCompat(window, window.decorView).apply { isAppearanceLightStatusBars = false // 适配浅色文字 } }
内容的提问来源于stack exchange,提问作者isifzade
相关产品推荐
相关产品推荐

