First, get access to the underlying view component
val view = LocalView.current
then in your button’s onClick
event, add the following line
view.playSoundEffect(SoundEffectConstants.CLICK)
That’s it. Now you have tap sounds in jetpack compose button.
Here’s a complete example
@Composable
fun MyComposable(){
val view = LocalView.current
Button(onClick = {
view.playSoundEffect(SoundEffectConstants.CLICK)
}){
Text("Click Me")
}
}