为什么用Toast,而不是AlertDialog

来源:互联网 发布:机构版交易软件 编辑:程序博客网 时间:2024/05/22 05:02

之前用其他平台,比如win32或者wp的时候,一直都是MessageBox,感觉MessageBox对话框还是比较好用的。之后做android开发,意外的发现androidAlertDialog以及Toast,一直在想为什么有了AlertDialog还需要Toast

为什么Android会出现Toast

首先看下Google官方的关于Toast class解释。

A toast is a view containing a quick little message for the user. The toast class helps you create and show those.

Toast是一个包含了简短信息的视图。Toast类帮助你创建以及显示它们。

When the view is shown to the user, appears as a floating view over the application. It will never receive focus. The user will probably be in the middle of typing something else. The idea is to be as unobtrusive as possible, while still showing the user the information you want them to see. Two examples are the volume control, and the brief message saying that your settings have been saved.

当视图被显示时,在应用程序上出现一个浮动的图层。它永远不能被聚焦(即无法响应各种点击事件等等)。用户可能正在中间输入什么。Toast设计被用来尽量不引人注目,但是又要想用户显示你(开发者)向要他们看到的东西。两个例子就是音量控制,以及简短的设置已保存的信息。

The easiest way to use this class is to call one of the static methods that constructs everything you need and returns a new Toast object.

最简单的使用该类的办法就是调用静态构造函数构造你需要的所有的东西,然后静态函数返回一个新的Toast对象。


从官方说明来看,Toast是为了不过分的打扰用户,但是又想让用户看到一些信息的一个解决方案。Toast在显示完信息后,一段时间,会自动关闭,根本无需用户有任何操作。但如果要持续的更新一些信息,Toast就不太好用了,需要用Notification

而对话框是为了引起用户注意,或者作出一些选择的时候才出现的。

从细节上来说,Toast是一个很好的解决方案吗,比Win32的一刀切的MessageBox好多了,很多时候用MessageBox的时候根本没有什么重要的信息,用户还得专门去把它关掉。

不得吐槽下Android下创建一个对话框(AlertDialog)真是麻烦,要写那么多代码,而Win32或者Windows Phone那么简单(跟Toast那样,一行简单的代码就可以搞定)。


转载请注明,禁止用于商业用途。

原创粉丝点击