[英]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.