问题
I have this code:
Button boton = (Button) findViewById(R.id.boton);
boton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
}
});
when I push my button (in Android 4.0.3) I ear a basic sound (a simply click); Can I replace it with a personal sound? Or I can use only MediaPlayer to play a costum sound?
回答1:
Try this:
public class MyActivity extends Activity {
public MyActivity(Bundle onSavedStateInstance) {
MediaPlayer mp = MediaPlayer.create(this, R.raw.mamacita_zero);
Button zero = (Button)this.findViewById(R.id.btnZero);
zero.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
mp.start();
}
});
}
}
回答2:
You can add sound to your raw folder, initialize it
MediaPlayer mpSplash = MediaPlayer.create(this, R.raw.slow);
and call it where ever required
mpSplash.start();
来源:https://stackoverflow.com/questions/12142541/android-replace-sound-of-onclick