61

How to disable click sound of a particular button in Android app?

Here is my code:

more1after.setOnClickListener(new OnClickListener() {
            public void onClick(View v) {
                sc.scrollTo(sc.getScrollX() + 75,
                sc.getScrollY() + sc.getWidth() + 5);
            }
        });
Johnny Five
  • 987
  • 1
  • 14
  • 29
Ankit HTech
  • 1,863
  • 6
  • 31
  • 42

4 Answers4

128

Try this code for disable button click sound effect:

yourbutton.setSoundEffectsEnabled(false);

(or) Layout XML file

 <Button... android:soundEffectsEnabled="false"/>
Dinesh
  • 6,500
  • 10
  • 42
  • 77
  • setSoundEffectsEnabled i have set it to false on one of my button but no effect. it still produce sound. tested on Google Nexus 10 – Muhammad Babar Jan 01 '14 at 12:04
  • 1
    the problem was with performClick() it doesn't respect the `setSoundEffectsEnabled(false)` – Muhammad Babar Jan 01 '14 at 12:28
  • 4
    @MuhammadBabar The solution to that seems to use the xml attribute instead of do it programatically `android:soundEffectsEnabled="false"` – 4gus71n Apr 15 '15 at 16:14
46

In case anyone wonders, here is the XML way:

<Button
    ...
    android:soundEffectsEnabled="false" />
yildirimyigit
  • 3,013
  • 4
  • 25
  • 35
3

For those who write code in Kotlin.

button.isSoundEffectsEnabled = false
Alfred Afutu
  • 191
  • 3
3
<Button
    ......
    android:soundEffectsEnabled="false"/>

Java code

button = findViewbyId(R.id.YourBUttonID);
button.setSoundEffectsEnabled(false);