Use activity window.attributes in Jetpack Compose to change screenBrightness

I am trying to modify screenBrightness through update this:

   window.attributes = window.attributes.apply { screenBrightness = 0.2f }

But I can get window in MainActivity : ComponentActivity() only. How to access is from Composable component?


  • I am using this to modify screen brightness in Jetpack Compose

    fun ComposableComponent() {
      val activity = LocalView.current.context as? Activity
      if (activity != null) {
        activity.window?.attributes = activity.window.attributes.apply {
          screenBrightness = -1.0f