为什么我不能在点击按钮时将mp3声音和过渡效果放到我的按钮上? 启动活动2时,我的应用程序崩溃了。如何使用媒体播放器和我的过渡效果到我的按钮在私人视图中单击.OnClickListener?
我正在使用库中的过渡效果(蹦极(
我的代码...
public class Activity2 extends AppCompatActivity {
private Button button3;
private Button entrycity;
private static final String NAME = "name";
private boolean isEnabled;
private SharedPreferences sharedPreferences;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
requestWindowFeature(Window.FEATURE_NO_TITLE);
getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN);
setContentView(R.layout.activity_2);
button3 = findViewById(R.id.button3);
button3.setOnClickListener(onButton1Click);
entrycity = findViewById(R.id.entrycity);
entrycity.setOnClickListener(onButton2Click);
sharedPreferences = getSharedPreferences(NAME, MODE_PRIVATE);
isEnabled = sharedPreferences.getBoolean(winflagi.IS_ENABLED, false);
entrycity.setEnabled(isEnabled);
if (isEnabled){
entrycity.setBackgroundResource(R.drawable.oval);
}
else {
entrycity.setBackgroundResource(R.drawable.oval3);
}
}
final MediaPlayer mp = MediaPlayer.create(this, R.raw.menunewquite);
private View.OnClickListener onButton1Click = new View.OnClickListener() {
@Override
public void onClick(View v) {
startActivity(new Intent(Activity2.this, flagi1.class));
mp.start();
Bungee.fade(this);
}
};
private View.OnClickListener onButton2Click = new View.OnClickListener() {
@Override
public void onClick(View v) {
startActivity(new Intent(Activity2.this, cities1.class));
mp.start
Bungee.fade(this);
}
};
}
尝试在侦听器体内声明 MediaPlayer。