ccd
ccd

Reputation: 6908

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

Upvotes: 14

Views: 9609

Answers (1)

Gabriele Mariotti
Gabriele Mariotti

Reputation: 363737

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

Upvotes: 19

Related Questions