ngl*_*ber 3

我尝试了这个答案并且工作了......

无法使用 playSoundEffect(SoundEffectConstants.CLICK) 单击按钮时播放声音

val context = AmbientContext.current
...

OutlinedButton(
    content = { Text("OK") },
    onClick = {
        val audioManager = context.getSystemService(Context.AUDIO_SERVICE) as AudioManager
        audioManager.playSoundEffect(SoundEffectConstants.CLICK,1.0f)
    }
)
Run Code Online (Sandbox Code Playgroud)

  • 嗯,看起来像是一种解决方法,而不是惯用的解决方案。我期望 Button() 或其 Modifier() 的一些特定参数,但找不到任何东西...... (5认同)