Search code examples
kotlindesktopandroid-jetpack-compose

Minimize/Maximize window in Jetpack Compose


Is there a way to maximize or minimize programmatically the window with Jetpack Compose Desktop ?

I'm thinking about that :

fun main() {
    application {
        Window(
            title = "My Application",
            focusable = true,
            onCloseRequest = { exitApplication() }
        ) {
            MyMaterialTheme {
                Button(onClick = { ...Minimize or Maximize... }) {
                    Text("Test")
                }
            }
        }
    }
}

Solution

  • Yes, You can do it by this:

    
    fun main() {
        val state = rememberWindowState()
    
        application {
            Window(
                state = stateAddress
            ) {
                MyMaterialTheme {
                    Button(onClick = { state.isMinimized = state.isMinimized.not() }) {
                        Text("Frms")
                    }
                }
            }
        }
    }