[英]Kill the Toast Message
在我的应用程序中,有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();
}
});
您需要为烤面包增加持续时间,这就是烤面包自我毁灭的方式。
Context context = getApplicationContext();
CharSequence text = "Hello toast!";
int duration = Toast.LENGTH_SHORT;
Toast toast = Toast.makeText(context, text, duration);
toast.show();
您可以找到许多有关烤面包实施的示例。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.