In my application I am using sound pool for the button click audio effect. The problem is that if in the device's settings "Audible selection" is ticked, then my buttons will produce two sounds: the system one and my one at the same time.
It seems that if in each button properties I set "Sound Effects Enabled" to false, the system sound is not heard any more. But I have many buttons across a dozen of activities, plus I am adding a matrix of buttons in code, so it is rather inconvenient to set "Sound Effects Enabled" to false manually for each one of them. Not sure how I do this in code..
Is there a more global way to stop "Audible selection" in my application or at least for the one activity?
Create a theme file "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>
And then reference to it in your "AndroidManifest.xml"
<application
...
android:theme="@style/AppTheme" >
I just had the same problem for my application. I was able to turn off sound feedback globally by putting android:soundEffectsEnabled=false
in a theme.
You could create your own Button class and use that in the XML layout files...
package com.mycompany.myApp
public class MyButton extends Button {
public MyButton (Context context, AttributeSet attrs) {
this.setSoundEffectsEnabled(false);
}
}
Then in the XML layout files use...
<com.mycompany.myApp.MyButton
...
</com.mycompany.myApp.MyButton>
...for your Buttons.
You could create a custom view that extends from Button. Then just set the Sound Effect Enabled to false on its creation.
http://developer.android.com/guide/topics/ui/custom-components.html
You can also go further and make the view know which new custom sound should be played.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With