[英]facing problem in changing status bar color in jetpack compose
我的应用程序中有两个活动,一个是home.kt
,另一个是about.kt
,对于两个屏幕,我都有不同的背景颜色,在home.kt
文件中,我将状态栏颜色设置为背景颜色。
rememberSystemUiController().setStatusBarColor(
MaterialTheme.colors.background, darkIcons = MaterialTheme.colors.isLight
)
当我移动到about.kt
我再次尝试将其颜色与背景匹配,但状态栏保持其在home.kt
中设置的原始颜色
rememberSystemUiController().setStatusBarColor(
MaterialTheme.colors.surface, darkIcons = MaterialTheme.colors.isLight
)
//This piece is having no effect
在每个活动中,而不是使用:
rememberSystemUiController().setStatusBarColor
,
使用这个(用你的背景颜色替换 0xff0000):
activity.window?.setStatusBarColor(0xff0000)
把它放在你的可组合中,这样每次你的可组合重新组合时它都会被调用。
为此,谷歌也创建了一个名为伴奏的库。 你可以在这里找到它: https : //github.com/google/accompanist
就像在这个模块中有多个模块用于jetpack compose,系统控制器,因此您可以使用它进行更改
如需更多了解,请参阅文档:-- https://google.github.io/accompanist/systemuicontroller/
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.