如何为我的所有应用程序或活动禁用默认声音效果

Lum*_*mis 36 android

在我的应用程序中,我使用声音池按钮单击音频效果.问题是如果在设备的设置中勾选了"Audible selection",那么我的按钮将产生两个声音:系统1和我的同时.

似乎如果在每个按钮属性中我将"Sound Effects Enabled"设置为false,则不再听到系统声音.但是我在十几个活动中有很多按钮,而且我在代码中添加了一个按钮矩阵,所以将"Sound Effects Enabled"设置为false来为每个按钮设置为非常不方便.不知道我是如何在代码中这样做的..

是否有一种更全面的方式来阻止我的应用程序中的"Audible selection"或至少针对一项活动?

Dav*_*las 52

创建主题文件"res/values/styles.xml"

<?xml version="1.0" encoding="utf-8"?>
<resources>

<style name="AppBaseTheme" parent="android:Theme.Black.NoTitleBar">
    <!--
        Theme customizations available in newer API levels can go in
        res/values-vXX/styles.xml, while customizations related to
        backward-compatibility can go here.
    -->
</style>

<!-- Application theme. -->
<style name="AppTheme" parent="AppBaseTheme">
    <!-- All customizations that are NOT specific to a particular API-level can go here. -->
    <item name="android:soundEffectsEnabled">false</item>
</style>

</resources>
Run Code Online (Sandbox Code Playgroud)

然后在"AndroidManifest.xml"中引用它

<application
    ...
    android:theme="@style/AppTheme" >
Run Code Online (Sandbox Code Playgroud)

  • 我也是这样做的.但它不适用于三星Note I. (4认同)
  • 在Lollipop不适合我 (2认同)

小智 29

我的应用程序遇到了同样的问题.通过android:soundEffectsEnabled=false插入主题,我能够在全球范围内关闭声音反馈.


Squ*_*onk 10

您可以创建自己的Button类并在XML布局文件中使用它...

package com.mycompany.myApp

public class MyButton extends Button {

    public MyButton (Context context, AttributeSet attrs) {
        this.setSoundEffectsEnabled(false);
    }
}
Run Code Online (Sandbox Code Playgroud)

然后在XML布局文件中使用...

<com.mycompany.myApp.MyButton
    ...
</com.mycompany.myApp.MyButton>
Run Code Online (Sandbox Code Playgroud)

...为你的按钮.