播放按钮点击音效 (CLICK/NAVIGATION_RIGHT) - Android [英] Playing sound effect (CLICK/NAVIGATION_RIGHT) for button clicks - Android
本文介绍了播放按钮点击音效 (CLICK/NAVIGATION_RIGHT) - Android的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在尝试使用 playSoundEffect ()
方法在单击按钮时播放声音效果,但到目前为止,由于某种原因,它被证明非常困难.
I'm trying to use the playSoundEffect ()
method to play a sound effect when a button is clicked, but so far its' proved very difficult for some reason.
我已经定义了以下内容.
I have defined the following.
<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() 方法中调用.但是当我点击按钮时,我似乎无法让它发出声音.我在这里错过了什么?文档没有什么可做的.
is called in onCreate() method. But I cannot seem to get it to sound when I click the button. What am I missing here? The documentation has nothing much to go on.
是否需要在 onClick() 方法中定义/调用?
Do I need to define/call in the onClick() method?
感谢任何帮助.
推荐答案
试试这个:
button_flip.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
button_flip.playSoundEffect(0);
}
});
值 0 代表 CLICK 声音.您可以在此处
The value 0 stands for CLICK sound. You can see more values here
这篇关于播放按钮点击音效 (CLICK/NAVIGATION_RIGHT) - Android的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文