试图让我的切换按钮来制作自定义声音,但我无法得到它,我是eclipse的新手,我设法在启动画面上获取它但却无法获得按钮。< / p>
package org.iimed.www;
import android.media.MediaPlayer;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.ImageButton;
import android.widget.ToggleButton;
import android.app.Activity;
import android.content.Context;
import android.content.Intent;
public class vpbox extends Activity {
private ImageButton home;
public void onCreate(Bundle vpbox_activity) {
super.onCreate(vpbox_activity);
setContentView(R.layout.vpbox_activity);
tuetoggle = (ToggleButton) findViewById(R.id.tuetoggle);
home = (ImageButton) findViewById(R.id.home);
home.setOnClickListener(new OnClickListener(){
@Override
public void onClick(View v){
startActivity(new Intent(vpbox.this, MainActivity.class));
ToggleButton sb = (ToggleButton) findViewById(R.id.suntoggle);
sb.setText(null);
sb.setTextOn(null);
sb.setTextOff(null);
sb.setBackgroundResource(R.drawable.vpbuttons);
ToggleButton mt= (ToggleButton)findViewById (R.id.montoggle);
mt.setText(null);
mt.setTextOn(null);
mt.setTextOff(null);
mt.setBackgroundResource(R.drawable.vpmonday);
ToggleButton wt = (ToggleButton) findViewById(R.id.wedtoggle);
wt.setText(null);
wt.setTextOff(null);
wt.setTextOn(null);
wt.setBackgroundResource(R.drawable.vpwed);
ToggleButton ft = (ToggleButton) findViewById(R.id.fritoggle);
ft.setText(null);
ft.setTextOn(null);
ft.setTextOff(null);
ft.setBackgroundResource(R.drawable.vpfri);
带声音的测试按钮:
ToggleButton thb = (ToggleButton) findViewById(R.id.thutoggle);
thb.setText(null);
thb.setTextOn(null);
thb.setTextOff(null);
thb.setBackgroundResource(R.drawable.vpthu);
MediaPlayer mp= MediaPlayer.create(getBaseContext(), R.raw.splashsound);
mp.start();