When implementing the app functionality in a classic Android (XML-based layouts) I had a tap sound enabled by default, I can hear it if an appropriate mode is set on the device.
However, I've noticed that it does not work out of the box for the functionality written in Jetpack Compose. How to enabled the default button click sound without updating every Button and interaction source modifiers?
I tried adding click sound manually, but it creates a mess in a codebase. How to achieve it in a simpler way? Compose is now a preferrable way to develop in Android, so I think it should be some way to do that simpler.
You simply have to add this to your clickable modifier:
val view = LocalView.current
For a custom button:
modifier = Modifier
.fillMaxSize()
.clickable() {
view.playSoundEffect(SoundEffectConstants.CLICK)}
otherwise:
Button(onClick = { view.playSoundEffect(SoundEffectConstants.CLICK) }) {}
It's not a system-wide solution but it does not require much code.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With