Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
282 views
in Technique[技术] by (71.8m points)

android - How to disable default sound effects for all my application or activity

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?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

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" >

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...