播放音效(点击/ NAVIGATION_RIGHT)的按钮点击 - 机器人 [英] Playing sound effect (CLICK/NAVIGATION_RIGHT) for button clicks - Android

查看:233
本文介绍了播放音效(点击/ NAVIGATION_RIGHT)的按钮点击 - 机器人的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图使用 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?

任何帮助是AP preciated。

Any help is appreciated.

感谢你。

推荐答案

试试这个:

button_flip.setOnClickListener(new View.OnClickListener() {

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

值为0表示咔嚓声。你可以看到更多的价值这里

这篇关于播放音效(点击/ NAVIGATION_RIGHT)的按钮点击 - 机器人的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆