androidandroid-jetpack-composeandroid-compose-button

How to custom the color of IconButton


I want to custom the color of IconButton instead of using the default value set on TopAppBar, but in android.compose.material there is no slot api to change it.

    Scaffold(
        topBar = {
            TopAppBar(
                title = {
                    Text(text = "LayoutsCodelab")
                },
                actions = {
                    IconButton(onClick = { /* doSomething() */ }) {  // <- why it has the theme color and how to custom it.
                        Icon(Icons.Filled.Favorite)
                    }
                }
            )
        }
    )

Solution

  • You can use the tint parameter in the Icon composable:

    actions = {
        IconButton(onClick = { /* doSomething() */ }) {
            Icon(Icons.Filled.Add,
                "contentDescription",
                tint = Color.Red)
        }
    }
    

    enter image description here