我的应用中有一个组件,其中是Toast,每次用户按Button的时候就会显示一个Toast。为了减少排队时间我像方法传递了一个值,这样它可以一直运行到周期结束。
代码:
dt("on button press");
private void dt(final String message) {
TextView text = (TextView) layout.findViewById(R.id.totext);
toast = new Toast(getApplicationContext());
toast.setGravity(Gravity.BOTTOM, 0, 0);
toast.setDuration(Toast.LENGTH_SHORT);
toast.setView(layout);
toast.cancel();
text.setText(message);
text.setTextSize(16);
toast.show();
}
问题是代码可以在Gingerbread和其他低版本中运行,但是不能在ICS和Jelly Bean中运行,这是为什么?有办法解决么?谢谢