添加Toast消息关闭时的回调



我有一个Toast消息,我用它作为启动屏幕,我想在它关闭后添加一个回调。这在安卓系统中是如何实现的?

// Splash
LayoutInflater inflater = getLayoutInflater();
View layout = inflater.inflate(R.layout.splash, (ViewGroup) findViewById(R.id.frameLayout1));
layout.setBackgroundColor(Color.WHITE);
Toast toast = new Toast(getApplicationContext());
toast.setGravity(Gravity.CENTER_VERTICAL, 0, 0);
toast.setDuration(Toast.LENGTH_LONG);
toast.setView(layout);
toast.show();

我没有对此进行测试,但您可能可以在传递给toast的视图中添加一个visibilitychanged监听器,请参阅http://developer.android.com/reference/android/view/View.html#onWindowVisibilityChanged(int)

或者,您可以使用getDuration()获取的toast持续时间设置计时器

你用吐司做这个有什么原因吗?为什么不在定义的时间段后使用setview或使用单独的"活动"更新视图?

最新更新