当我在stackoverflow中搜索吐司时,我发现了许多与我的问题有关的东西。但是他们都没有解决我的问题。在我的Android应用程序中,我应该在彼此之后显示许多祝酒词。但是当我尝试这样做时,接下来的吐司等待当前的吐司完成。即使我使用取消吐司,在我看来它永远不会奏效。请给我一个确切的解决方案。谢谢你..
inflater = getLayoutInflater();
backgForToast=(ViewGroup) findViewById(R.id.toast_layout_root);
layout = inflater.inflate(R.layout.toastbackground,backgForToast);
textForToast = (TextView) layout.findViewById(R.id.text);
textForToast.setText(toastMessage);
toast.setGravity(Gravity.TOP|Gravity.LEFT, toastX2-90,toastY2-90);
toast.setView(layout);
toast.show();
Handler handler = new Handler();
long delay = 500;
handler.postDelayed(new Runnable() {
@Override
public void run() {
toast.cancel();
}
}, delay);
答案 0 :(得分:1)
您需要先使用Toast
创建一个Toast.makeText
对象,然后才能cancel()
。
答案 1 :(得分:1)
这是取消 DateTime timeUtc = DateTime.UtcNow;
try
{
TimeZoneInfo cstZone = TimeZoneInfo.FindSystemTimeZoneById("Central Standard Time");
DateTime cstTime = TimeZoneInfo.ConvertTimeFromUtc(timeUtc, cstZone);
Console.WriteLine("The date and time are {0} {1}.",
cstTime,
cstZone.IsDaylightSavingTime(cstTime) ?
cstZone.DaylightName : cstZone.StandardName);
}
catch (TimeZoneNotFoundException)
{
Console.WriteLine("The registry does not define the Central Standard Time zone.");
}
catch (InvalidTimeZoneException)
{
Console.WriteLine("Registry data on the Central STandard Time zone has been corrupted.");
}
:
Toast