How to custom the color of IconButton

7.9k views Asked by At

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)
                    }
                }
            )
        }
    )
1

There are 1 answers

4
Gabriele Mariotti On BEST ANSWER

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