4

I can disable system clicking sound on a button if I use android:soundEffectsEnabled="false" in its layout.

I want to disable the sound effect on an Action Bar item. This attribute seems to make no difference.

How can I disable clicking sounds when user selects a menu item?

AstroCB
  • 12,337
  • 20
  • 57
  • 73
iter
  • 4,171
  • 8
  • 35
  • 59
  • 1
    If you're going to downvote, consider explaining what you dislike about this question. – iter Aug 31 '14 at 00:46
  • 1
    I agree with you. There's nothing wrong with the question, so I've upvoted it. However in my experience trying to customise the action bar is a total nightmare, and just because you get it working on one device doesn't mean it will work on all devices. If you value your sanity I wouldn't try. The click sound is less annoying on newer devices anyway. – Paul Boddington Aug 31 '14 at 16:12
  • 1
    I'm beginning to wonder if this is even possible. I needed to disable the Menu Item clicking sound, since I'm using the Menu Item to record audio. For a work-a-round, I just delayed the recording for a few milliseconds. I would still like to find a solution to this though... – wizurd Sep 07 '14 at 18:29

2 Answers2

0

I use this:

    final Toolbar toolbar = (Toolbar) this.findViewById(R.id.toolbar);
    final View child = toolbar.getChildAt(2);
    if (child instanceof ActionMenuView)
    {
        final ActionMenuView actionMenuView = ((ActionMenuView) child);
        actionMenuView.getChildAt(actionMenuView.getChildCount() - 1).setSoundEffectsEnabled(false);
    }

If have navigation drawer use toolbar.getChildAt(2); if not use toolbar.getChildAt(1);

gogoloi
  • 627
  • 3
  • 8
  • 19
0

Was able to get this working in Android 11 by disabling sound effects for the view (in this case, an ImageView) associated with the action bar item. Hopefully this helps someone...

View view = menuItem.getActionView();
if (view != null) {
    view.setSoundEffectsEnabled(false);
}
mbonness
  • 1,612
  • 1
  • 18
  • 20