gpt4 book ai didi

android - 播放按钮点击的音效 (CLICK/NAVIGATION_RIGHT) - Android

转载 作者:太空宇宙 更新时间:2023-11-03 13:06:22 24 4
gpt4 key购买 nike

我正在尝试使用 playSoundEffect () 方法在单击按钮时播放声音效果,但由于某些原因到目前为止它被证明非常困难。

我定义了以下内容。

<ImageButton android:id="@+id/Button_flip" android:layout_width="fill_parent"
android:layout_height="wrap_content" android:text="FLIP!"
android:src="@drawable/flip" android:soundEffectsEnabled="true">
</ImageButton>

然后,

button_flip.playSoundEffect(android.view.SoundEffectConstants.CLICK);

在 onCreate() 方法中被调用。但是当我点击按钮时,我似乎无法让它发出声音。我在这里错过了什么?该文档没有太多内容。

是否需要在onClick()方法中定义/调用?

感谢任何帮助。

最佳答案

试试这个:

button_flip.setOnClickListener(new View.OnClickListener() {

@Override
public void onClick(View v) {
// TODO Auto-generated method stub
button_flip.playSoundEffect(0);
}
});

值 0 代表 CLICK 声音。可以看到更多的值here

关于android - 播放按钮点击的音效 (CLICK/NAVIGATION_RIGHT) - Android,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3905651/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com