【翻译】(18)通知

本文介绍了Android平台上的三种主要通知方式:Toast通知、状态栏通知和对话框通知的特点及应用场景。Toast适用于简短消息提示;状态栏通知适合后台进程的重要事件提醒;对话框通知则常用于与当前Activity直接相关的事件。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

 

【翻译】(18)通知

 

see

http://developer.android.com/guide/topics/ui/notifiers/index.html

 

原文见

http://developer.android.com/guide/topics/ui/notifiers/index.html

 

-------------------------------

 

Notifications

 

通知

 

Several types of situations may arise that require you to notify the user about an event that occurs in your application. Some events require the user to respond and others do not. For example:

 

有几种类型的情况可能会导致需要你通知用户关于一个发生在你的应用程序内的事件。一些事件需要用户响应而其它则不需要。例如:

 

* When an event such as saving a file is complete, a small message should appear to confirm that the save was successful.

 

* 当一个事件诸如文件保存已经完成,一个小的消息应该出现以肯定保存是成功的。

 

* If the application is running in the background and needs the user's attention, the application should create a notification that allows the user to respond at his or her convenience.

 

* 如果应用程序运行在后台并且需要用户注意,应用程序应该创建一个通知以允许用户在方便的时候响应。

 

* If the application is performing work that the user must wait for (such as loading a file), the application should show a hovering progress wheel or bar.

 

* 如果应用程序正在执行用户必须等待的工作(诸如加载文件),应用程序应该显示一个悬浮的进度轮或进度条。

 

Each of these notification tasks can be achieved using a different technique:

 

这些通知任务的每一种可以用不同的技术实现。

 

* A Toast Notification, for brief messages that come from the background.

 

* Toast通知,用于来自后台的简短消息。

 

* A Status Bar Notification, for persistent reminders that come from the background and request the user's response.

 

* 状态栏通知,用于来自后台的持久提醒并请求用户的响应。

 

* A Dialog Notification, for Activity-related notifications.

 

* 对话框通知,用于与Activity有关的通知。

 

This document summarizes each of these techniques for notifying the user and includes links to full documentation.

 

本文总结这些用于通知用户的技术的每一种并包含完整文档的链接

 

-------------------------------

 

Toast Notification

 

Toast通知

 

(图略:

这个闹钟被设置为从现在开始17小时又57分钟之后。

 

A toast notification is a message that pops up on the surface of the window. It only fills the amount of space required for the message and the user's current activity remains visible and interactive. The notification automatically fades in and out, and does not accept interaction events. Because a toast can be created from a background Service, it appears even if the application isn't visible.

 

Toast通知是一种在窗口表面上弹出的消息。它只填充消息所需数量的空间,而用户的当前活动保持可见和可交互。通知自动地淡进和淡出,并且不会接受任何交互事件。因为一个Toast可以从后台Service中创建,所以即便应用程序不可见它仍会显示。

 

A toast is best for short text messages, such as "File saved," when you're fairly certain the user is paying attention to the screen. A toast can not accept user interaction events; if you'd like the user to respond and take action, consider using a Status Bar Notification instead.

 

Toast最适合短文本消息,诸如在你大概肯定用户正在注意屏幕时显示“文件已保存”。一个Toast不能接受用户交互事件;如果你喜欢用户响应和采取动作,请考虑使用状态栏消息代替它。

 

For more information, refer to Toast Notifications.

 

想获取更多信息,请参考Toast消息。

 

-------------------------------

 

Status Bar Notification

 

状态栏通知

 

(图略:

2009年4月25日 下午3:41

Android 清空通知

通知

特拉维斯

你在哪里? 下午3:39

 

A status bar notification adds an icon to the system's status bar (with an optional ticker-text message) and an expanded message in the "Notifications" window. When the user selects the expanded message, Android fires an Intent that is defined by the notification (usually to launch an Activity). You can also configure the notification to alert the user with a sound, a vibration, and flashing lights on the device.

 

状态栏通知添加一个图标到系统的状态栏(带有一个可选的纸带文本消息)以及在“通知”窗口中的一个可展开的消息。当用户选择被展开的消息时,Android发送一个被通知定义的Intent对象(通常用来启动一个Activity)。你还可以配置通知在设备上用声音,震动,和闪光来提醒用户。

 

This kind of notification is ideal when your application is working in a background Service and needs to notify the user about an event. If you need to alert the user about an event that occurs while your Activity is still in focus, consider using a Dialog Notification instead.

 

此类通知是理想的,当你的应用程序正在工作在后台Service并且需要通知用户一个事件。如果你需要提醒用户一个发生在你的Activity仍然处于焦点时的事件,请考虑使用一个对话框通知代替它。

 

For more information, refer to Status Bar Notifications.

 

想获取更多信息,请参考状态栏通知。

 

-------------------------------

 

Dialog Notification

 

对话框通知

 

(图略:

正在加载。请稍候……

 

A dialog is usually a small window that appears in front of the current Activity. The underlying Activity loses focus and the dialog accepts all user interaction. Dialogs are normally used for notifications and short activities that directly relate to the application in progress.

 

对话框通常是一个显示在当前Activity前方的小窗口。底下的Activity失去焦点而对话框接受所有用户交互。对话框通常用于在进度中直接与应用程序关联的通知和短的活动。

 

You should use a dialog when you need to show a progress bar or a short message that requires confirmation from the user (such as an alert with "OK" and "Cancel" buttons). You can use also use dialogs as integral components in your application's UI and for other purposes besides notifications. For a complete discussion on all the available types of dialogs, including its uses for notifications, refer to Dialogs.

 

在你需要显示一个进度条或一个需要来自用户的确定的短消息(诸如一个带有“确定”和“取消”按钮的警告)时,你应该使用一个对话框。你可还可以使用对话框作为你的应用程序的用户界面中的集成组件并用于除通知外的其它目的。想获取一个关于所有可用类型对话框的完整讨论,包括它用于通知的使用方法,请参考对话框。

 

Except as noted, this content is licensed under Apache 2.0. For details and restrictions, see the Content License.

 

除特别说明外,本文在Apache 2.0下许可。细节和限制请参考内容许可证。

 

Android 4.0 r1 - 01 Dec 2011 20:53

 

-------------------------------

 

Portions of this page are modifications based on work created and shared by the Android Open Source Project and used according to terms described in the Creative Commons 2.5 Attribution License.

 

(此页部分内容基于Android开源项目,以及使用根据创作公共2.5来源许可证描述的条款进行修改)

 

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值