android - 如何自定义 IconButton 的颜色

标签 android android-jetpack-compose android-compose-button

我想自定义 IconButton 的颜色,而不是使用 TopAppBar 上设置的默认值,而是使用 android.compose.material没有插槽 api 可以更改它。

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

最佳答案

您可以使用 tint Icon 中的参数可组合:

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

关于android - 如何自定义 IconButton 的颜色,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/64424206/

相关文章:

android - Jetpack Compose 中按钮的背景颜色

Android 线程间通信

Android:将 ACTION_PICK_ACTIVITY 与 AppWidget 结合使用来确定在按下时打开哪个应用程序

android-jetpack-compose - 检测逆时针旋转输入,Wear OS Jetpack Compose

android - 修复 Jetpack Compose 按钮​​中心的文本位置

android - 在 AOSP 中编译和部署各个组件

Android:关闭listview的延迟加载

android-jetpack-compose - 具有 View 绑定(bind)的 ComposeView

android - 如何从文本按钮中删除填充?