如果在布局中使用android:soundEffectsEnabled="false",则可以禁用按钮上的系统单击声音。

我想在操作栏项上禁用声音效果。此属性似乎没有什么区别。

用户选择菜单项时如何禁用点击声音?

最佳答案

我用这个:

    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);
    }

如果有导航抽屉,请使用toolbar.getChildAt(2);。如果不使用工具栏.getChildAt(1);

07-28 02:20
查看更多