提问人:Dina 提问时间:11/9/2023 最后编辑:Dina 更新时间:11/24/2023 访问量:35
使用 Jetpack Compose 中的 Activity window.attributes 更改 screenBrightness
Use activity window.attributes in Jetpack Compose to change screenBrightness
问:
我正在尝试通过更新来修改screenBrightness:
window.attributes = window.attributes.apply { screenBrightness = 0.2f }
但是我只能在MainActivity:ComponentActivity()中获得窗口。如何从可组合组件访问?
答:
0赞
Dina
11/24/2023
#1
我正在使用它来修改 Jetpack Compose 中的屏幕亮度
@Composable
fun ComposableComponent() {
val activity = LocalView.current.context as? Activity
if (activity != null) {
activity.window?.attributes = activity.window.attributes.apply {
screenBrightness = -1.0f
}
}
}
评论