Jetpack Compose 未更新图标

jetpack compose not updating icon

标题会根据更改进行更新,但图标不会。

@Composable
fun topBar(title: String) {
    val context = LocalContext.current
    var showMenu by remember { mutableStateOf(false) }
    val health = remember { Health() }
    val healthMin = remember { mutableStateOf(R.drawable.music) }
    
    TopAppBar(title = {
        val location = remember { mutableStateOf("") }
        SystemBroadcastReceiver(MediaPlaybackService.LOCATION_CHANGE) { intent ->
            location.value = intent!!.getStringExtra(MediaPlaybackService.LOCATION_CHANGE)!!
        }

        Text(text = location.value)
    },
        navigationIcon = {
            SystemBroadcastReceiver(Health.STATUS) { intent ->
                health.onReceive(null, intent)
                healthMin.value = health.updateLogo()
            }

            IconButton(onClick = {}) {
                Log.i("TEST","Value = ${healthMin.value}")
                Icon(
                    painter = painterResource(healthMin.value),
                    "contentDescription"
                )
            }
        },
...

我可以在日志中看到变化。但是UI没有更新

2022-02-24 12:56:24.117 3032-3032/com.example.myapplication I/TEST: Value = 2131231223
2022-02-24 12:56:24.525 3032-3032/com.example.myapplication I/TEST: Value = 2131231226

SystemBroadcastReceiver 取自 case-study official documentaion

代码确实有效。我的问题是,视觉图标看起来没有变化,因为更改后的图标只有不同的颜色。颜色被色调所支配。所以变化是不可见的。

如果您想查看资源中的颜色而不是主题中的颜色,请使用此选项。

Icon( painter = painterResource(healthMin.value),
      tint = Color.Unspecified,
      "contentDescription"
)