openharmony 鸿蒙 ts-universal-attributes-click-sound

2026-08-25 浏览 (1)

Click Sound Effect

You can enable or disable the default click sound effect for a component.

NOTE

This API is supported since API version 24. Updates will be marked with a superscript to indicate their earliest API version.

enableClickSoundEffect

enableClickSoundEffect(enabled: boolean|undefined): T

Sets whether to enable the default click sound effect for a component. Whether the sound can be played depends on the sound settings of the device. For example, the sound effect is not played in mute mode.

Model restriction: This API can be used only in the stage model.

Atomic service API: This API can be used in atomic services since API version 24.

System capability: SystemCapability.ArkUI.ArkUI.Full

Device behavior differences: This API can be called on TVs but has no effect on other devices.

Parameters

NameTypeMandatoryDescription
enabledboolean | undefinedYesWhether to enable the default click sound effect for a component.
The value true indicates that the default click sound effect is enabled, and false indicates the opposite.
If the value is undefined, the default click sound effect is enabled.

Return value

TypeDescription
TCurrent component.

Example

Example 1: Enabling the Default Click Sound Effect

This example disables the default click sound effect by setting the enableClickSoundEffect attribute. You can call audio-related APIs in the onClick callback to customize the sound effect. For details, see Using SoundPool to Play Short Sounds.

The enableClickSoundEffect attribute is added since API version 24.

@Entry
@Component
struct Index {
  build() {
    Column() {
      Button('Click')
        .fontSize('20dp')
        .height('60')
        .width('200')
        .enableClickSoundEffect(false)
        .onClick(() => {
          // Customize the sound effect. For details, see the guide of using SoundPool.
        })
    }
    .width('100%')
    .height('100%')
    .justifyContent(FlexAlign.Center)
    .alignItems(HorizontalAlign.Center)
  }
}

你可能感兴趣的鸿蒙文章

openharmony 鸿蒙 ts-drawing-components-shape

openharmony 鸿蒙 ts-universal-attributes-sharp-clipping

openharmony 鸿蒙 ts-universal-attributes-toolbar

openharmony 鸿蒙 ts-container-lazyvgridlayout

openharmony 鸿蒙 ohos-arkui-advanced-FoldSplitContainer

openharmony 鸿蒙 ts-methods-calendarpicker-dialog

openharmony 鸿蒙 ts-uicommonevent

openharmony 鸿蒙 ts-basic-gestures-tapgesture

openharmony 鸿蒙 ohos-arkui-advanced-DialogV2

openharmony 鸿蒙 ts-components-canvas-canvas

  • 所属分类: 后端技术
  • 本文标签: 软件 鸿蒙
  • 版权声明: 本文链接 https://seaxiang.com/blog/oo9OcjTt