如何使用使用view.playSoundEffect(SoundEffectConstants.CLICK)默认的点击声; [英] How do I use the default click sound using view.playSoundEffect(SoundEffectConstants.CLICK);

查看:2316
本文介绍了如何使用使用view.playSoundEffect(SoundEffectConstants.CLICK)默认的点击声;的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我婉使用默认 TICK 的声音,但我不知道如何或在哪里把这个code

I wan to use the default TICK sound but I dont know how or where to put this code

view.playSoundEffect(SoundEffectConstants.CLICK);

我发现这个code在另一篇文章。

I found this code in another post.

这是在code,我有:

This is the code I have:

        protected void onCreate(Bundle savedInstanceState)
        {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        final MediaPlayer mp = MediaPlayer.create(this, R.raw.blah);

        Button Button01 = (Button)this.findViewById(R.id.Button01);
        Button01.setOnClickListener(new View.OnClickListener() 
        {
            public void onClick(View v) 
            {
                mp.start();
            }
        });
    }

    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        // Inflate the menu; this adds items to the action bar if it is present.
        getMenuInflater().inflate(R.menu.activity_main, menu);
        return true;
    }

    public void onClick(View v){}

    public void disclaimerBTN (View v){
        Toast.makeText(this, "FAILED:      The remote object is " +
                            "not responding to this command",Toast.LENGTH_LONG).show();
    }
}

那么,我会放在 view.play ..... code? 许多AP preciated。

So where would I put the view.play..... code? Much appreciated.

推荐答案

有关使用<一个href="http://developer.android.com/reference/android/media/AudioManager.html#playSoundEffect%28int,%20float%29">AudioManager.playSoundEffect在按钮单击事件,你可以尝试如下:

For Using AudioManager.playSoundEffect on Button click event you can try as:

AudioManager audioManager = 
            (AudioManager) this.getSystemService(Context.AUDIO_SERVICE);

 Button01.setOnClickListener(new View.OnClickListener() 
        {
            public void onClick(View v) 
            {
                 audioManager.playSoundEffect(SoundEffectConstants.CLICK);   
                 //mp.start();
            }
        });

仅供参考,你可以看到这样的例子在谷歌源$ C ​​$ C:

for reference you can see this example on Google source code:

<一个href="http://$c$c.google.com/p/android-traditional-chinese-ime/source/browse/trunk/src/com/google$c$c/tcime/SoundMotionEffect.java?r=13">http://$c$c.google.com/p/android-traditional-chinese-ime/source/browse/trunk/src/com/google$c$c/tcime/SoundMotionEffect.java?r=13

这篇关于如何使用使用view.playSoundEffect(SoundEffectConstants.CLICK)默认的点击声;的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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