57

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
  • 937
  • 1
  • 14
  • 29
Ankit HTech
  • 1,823
  • 5
  • 31
  • 42

4 Answers4

127

Try this code for disable button click sound effect:

yourbutton.setSoundEffectsEnabled(false);

(or) Layout XML file

 <Button... android:soundEffectsEnabled="false"/>
Dinesh
  • 6,470
  • 10
  • 41
  • 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,003
  • 4
  • 24
  • 35
2

For those who write code in Kotlin.

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

Java code

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