简体   繁体   English

在 jetpack compose 中更改状态栏颜色时遇到问题

[英]facing problem in changing status bar color in jetpack compose

I have two activities in my app, one is the home.kt and another is the about.kt , for both screens I have different background color, in the home.kt file I set the status bar color to background color.我的应用程序中有两个活动,一个是home.kt ,另一个是about.kt ,对于两个屏幕,我都有不同的背景颜色,在home.kt文件中,我将状态栏颜色设置为背景颜色。

rememberSystemUiController().setStatusBarColor(
    MaterialTheme.colors.background, darkIcons = MaterialTheme.colors.isLight
)

When I move to about.kt I again tried to match its color to background but the status bar keeps its original color which was set in home.kt当我移动到about.kt我再次尝试将其颜色与背景匹配,但状态栏保持其在home.kt中设置的原始颜色

rememberSystemUiController().setStatusBarColor(
    MaterialTheme.colors.surface, darkIcons = MaterialTheme.colors.isLight
)
//This piece is having no effect

In each activity, instead of using:在每个活动中,而不是使用:

rememberSystemUiController().setStatusBarColor , rememberSystemUiController().setStatusBarColor ,

use this (replace 0xff0000 with your background color):使用这个(用你的背景颜色替换 0xff0000):

activity.window?.setStatusBarColor(0xff0000)

Place that inside your composable so that it gets called each time your composable recomposes.把它放在你的可组合中,这样每次你的可组合重新组合时它都会被调用。

For that, too google has created a library called accompanist.为此,谷歌也创建了一个名为伴奏的库。 You can find it here: https://github.com/google/accompanist你可以在这里找到它: https : //github.com/google/accompanist

like in this module have multiple module for jetpack compose, system controller so you can change by using it就像在这个模块中有多个模块用于jetpack compose,系统控制器,因此您可以使用它进行更改

for more understanding see the document :-- https://google.github.io/accompanist/systemuicontroller/如需更多了解,请参阅文档:-- https://google.github.io/accompanist/systemuicontroller/

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 Jetpack Compose 状态栏颜色未在深色主题中更新 - Jetpack Compose status bar color not updated in Dark Theme Jetpack Compose 的状态栏中未显示模态底板稀松布颜色 - Modal Bottom Sheet scrim color is not shown in status bar in Jetpack compose SystemUIController 不会设置状态栏颜色 - Jetpack Compose Accompanist - SystemUIController won't set status bar color - Jetpack Compose Accompanist 在 Jetpack Compose 中设置状态栏颜色渐变匹配内容背景渐变 - Set status bar color gradient matching the content background gradient in Jetpack Compose Jetpack compose - 更改底部栏切口颜色 - Jetpack compose - change bottom bar cutout color 如何在 Jetpack Compose 对话框中绘制系统状态栏后面的绘图 - How to draw draw behind the system status bar in a Jetpack Compose Dialog 使用 Android 和 Jetpack Compose 仅更改一个状态栏 - Change just one status bar with Android and Jetpack Compose Android状态栏颜色不变 - Android status bar color not changing 更改状态栏图标颜色 - Changing status bar icon color jetpack compose 无法将搜索栏背景颜色设置为白色 - jetpack compose can't set search bar background color to white
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM