在我的应用程序中,有13个按钮具有不同的祝酒词。 当我点击另一个按钮时,吐司没有停止正常销毁,这是我的代码。
public class MainActivity extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Button one = (Button) this.findViewById(R.id.gg);
final MediaPlayer mp1 = MediaPlayer.create(this, R.raw.gg);
one.setOnClickListener(new View.OnClickListener(){
public void onClick(View v) {
Toast toast = Toast.makeText(MainActivity.this, "Good Game", Toast.LENGTH_SHORT);
toast.show();
mp1.start();
toast.cancel();
}
});
答案 0 :(得分:0)
答案 1 :(得分:0)
您需要为吐司添加持续时间,这就是吐司自毁的方式。
Context context = getApplicationContext();
CharSequence text = "Hello toast!";
int duration = Toast.LENGTH_SHORT;
Toast toast = Toast.makeText(context, text, duration);
toast.show();
你可以在吐司实现上找到很多例子。