Xamarin : android : 停用按鈕聲音

正常的狀況下,按下Android APP 內的按鈕 Button,裝置都會發出『達、達』『滴、滴』等的聲音,這個聲音不是 APP 產生或是開發出來的。

這是 Android 內置的系統聲音。

如果某些情境開發下,希望能夠關閉這個聲音,可以透過下面兩種方式實現:

1.針對按鈕 Button 操作屬性
程式方式:


button.setSoundEffectsEnabled(false);

屬性變更


<Button
    ...
    android:soundEffectsEnabled="false" />



2.針對全環境(APP)操作:
在資源檔內建立 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>



然後,在 AndroidManifest.xml 裡面,修改(不存在就增加)這一段,強制使用樣式檔


<application
    ...
    android:theme="@style/AppTheme" >



參考:
https://stackoverflow.com/questions/15293608/disable-button-click-sound-in-android
https://stackoverflow.com/questions/5023170/how-to-disable-default-sound-effects-for-all-my-application-or-activity


留言

這個網誌中的熱門文章

【研究】列印的條碼為什麼很難刷(掃描)

C# 使用 Process.Start 執行外部程式

統一發票列印小程式