Navigation with Back and Up Developer Docs

来源:互联网 发布:widowns无法连接网络 编辑:程序博客网 时间:2024/04/29 18:15

Navigation with Back and Up Developer Docs

带有回退键和向上键的导航栏 开发文档

Implementing Effective Navigation

Consistent navigation is an essential component of the overall user experience. Few things frustrate users more than basic navigation that behaves in inconsistent and unexpected ways. Thoughtfully following the guidelines for Back and Up will make your app’s navigation predictable and reliable for your users.
导航的一致性是整体用户体验的一个重要组成部分。作为基本功能的导航键,几乎没有比它产生不一致或者意料之外的响应更让用户感到困扰的事情了。认真参考以下指南,将使您的应用程序的导航栏更加可预见和可靠地为用户服务。

Action bars provide a second, standard navigation mechanism: the Up button, consisting of the app icon and a left-point caret.
ActionBars 提供了一个额外的标准导航机制:向上按钮,应用程序图标和一个向左的插入符号。

Up vs. Back

The Up button is used to navigate within an app based on the hierarchical relationships between screens. For instance, if screen A displays a list of items, and selecting an item leads to screen B (which presents that item in more detail), then screen B should offer an Up button that returns to screen A.
向上按键是用于根据应用程序中各个页面的层次关系进行导航的。例如,如果页面A显示一个项目列表,选中其中一个项目将进入页面B(该项目的详细介绍),此时页面B应该提供一个向上按键,用于返回到页面A。

If a screen is the topmost one in an app (that is, the app’s home), it should not present an Up button.
如果该页面位于应用页面层级关系的顶端(即应用的根界面),那么它不应该出现向上按键。

The system Back button is used to navigate, in reverse chronological order, through the history of screens the user has recently worked with. It is generally based on the temporal relationships between screens, rather than the app’s hierarchy.
系统后退按钮用于按逆时间顺序排列对用户最近的浏览的页面历史进行导航。它通常是基于屏幕之间的时序关系,而不是应用程序的层次结构。

When the previously viewed screen is also the hierarchical parent of the current screen, pressing the Back button has the same result as pressing an Up button—this is a common occurrence. However, unlike the Up button, which ensures the user remains within your app, the Back button can return the user to the Home screen, or even to a different app.
当上一个浏览的页面也是当前页面层级关系的父页面时,点击返回键和向上键是一样的,这是一个很常见的现象。不过,与向上键的操作范围始终在同一个应用所不同的是,返回键可以返回至主屏,甚至返回到另一个应用中。

The Back button also supports a few behaviors not directly tied to screen-to-screen navigation:
后退按钮也支持一些与screen-to-screen无直接关系的导航:

  • Dismisses floating windows (dialogs, popups)
  • 销毁浮动窗口(对话框,弹出窗口)
  • Dismisses contextual action bars, and removes the highlight from the selected items
  • 销毁具有上下文关系的action bar, 移除被选中项目的高亮显示
  • Hides the onscreen keyboard (IME)
  • 隐藏屏幕键盘

Navigating to screens with multiple entry points

支持多点进入页面的导航
Sometimes a screen doesn’t have a strict position within the app’s hierarchy, and can be reached from multiple entry points—such as a settings screen that can be reached from any other screen in your app. In this case, the Up button should choose to return to the referring screen, behaving identically to Back.
有时一个页面在应用程序的层次结构没有绝对的位置,就像settings的页面一样可以从多个条目进入(比如其他应用的页面)。在这种情况下,向上按键应该返回引用它的页面,与返回键的相应一致。

Changing view within a screen
改变页面中的视图
Changing view options for a screen does not change the behavior of Up or Back: the screen is still in the same place within the app’s hierarchy, and no new navigation history is created.
改变页面中的视图选项不会改变向上或回退的行为:页面仍然处于应用程序层次结构的同一个地方,并没有新的导航历史产生。

Examples of such view changes are:
改变页面中视图的例子有:

  • Switching views using tabs and/or left-and-right swipes
  • 使用tab键或者左右划动切换视图
  • Switching views using a dropdown (aka collapsed tabs)
  • 使用下拉菜单(又名倒着的tabs)
  • Filtering a list
  • 对列表进行筛选
  • Sorting a list
  • 给列表进行排序
  • Changing display characteristics (such as zooming)
  • 改变显示的特征(比如放大)

Navigating between sibling screens

When your app supports navigation from a list of items to a detail view of one of those items, it’s often desirable to support direction navigation from that item to another one which precedes or follows it in the list. For example, in Gmail, it’s easy to swipe left or right from a conversation to view a newer or older one in the same Inbox. Just as when changing view within a screen, such navigation does not change the behavior of Up or Back.
当您的应用程序支持从一个列表导航进入列表项的详细视图,在该项的详细视图中,通常提供方向导航用于进入列表中该项的前一项或者后一项的详细视图是非常可取的方式。比如,在Gmail的收件箱中,通过在一个会话(邮件)里左右滑动可以方便地浏览下一个或者前一个会话。就像这样改变页面中视图的时候,向上键或回退键的响应行为都不会发生改变。

However, a notable exception to this occurs when browsing between related detail views not tied together by the referring list—for example, when browsing in the Play Store between apps from the same developer, or albums by the same artist. In these cases, following each link does create history, causing the Back button to step through each previously viewed screen. Up should continue to bypass these related screens and navigate to the most recently viewed container screen.
不过,一个需要注意的例外是, 当所浏览的这些关联的细节视图并不是由同一个引用列表联系起来的,比如说,当浏览应用商店中同一个开发者开发的不同应用,或者同一个艺术家的不同专辑。在这些情况下,每个链接都会创建历史,导致了后退按钮将通过每一步去查看之前的页面。而向上按键将还是绕过这些相关的页面,直接导航到最接近的容器视图。

You have the ability to make the Up behavior even smarter based on your knowledge of detail view. Extending the Play Store example from above, imagine the user has navigated from the last Book viewed to the details for the Movie adaptation. In that case, Up can return to a container (Movies) which the user hasn’t previously navigated through.
基于对详细视图的了解,你可以使向上的操作更加智能。扩展上述游戏商店的例子,假设用户从图书介绍切换到电影改编的详细信息。在这种情况下,可以向上返回到一个用户之前没有浏览过的容器(电影)。

从桌面小组件和通知导览到你的应用

You can use Home screen widgets or notifications to help your users navigate directly to screens deep within your app’s hierarchy. For example, Gmail’s Inbox widget and new message notification can both bypass the Inbox screen, taking the user directly to a conversation view.
您可以使用桌面小组件或通知来帮助用户浏览应用的层次结构的深层页面。例如,Gmail收件箱部件和新消息通知既可以绕过收件箱界面,直接将视图呈现给用户。

For both of these cases, handle the Up button as follows:
对于这两种情况,可以像下面一样处理向上按键的响应

If the destination screen is typically reached from one particular screen within your app, Up should navigate to that screen.
Otherwise, Up should navigate to the topmost (“Home”) screen of your app.
通常,如果目标界面是从应用程序中的一个特定的界面切换过去的,那么向上则应该导航至该特定界面。
否则,向上导航应该切换到你的应用程序的顶层(“主”)界面。

In the case of the Back button, you should make navigation more predictable by inserting into the task’s back stack the complete upward navigation path to the app’s topmost screen. This allows users who’ve forgotten how they entered your app to navigate to the app’s topmost screen before exiting.
至于回退按键,你应该将向上导航至最顶层的界面的完整路径插入任务的后退堆栈中,以增强导航的可预测性。这样用户在能够返回到应用退出前的顶层界面,即使他们已经忘了来时操作的路径。

As an example, Gmail’s Home screen widget has a button for diving directly to its compose screen. Up or Back from the compose screen would take the user to the Inbox, and from there the Back button continues to Home.
例如,Gmail的主屏幕小部件有一个按钮是用于直接跳转到写邮件的界面。从写邮件界面向上或者回退,将跳转到用户的收件箱,而收件箱回退将返回主界面。

Indirect notifications
间接的通知
When your app needs to present information about multiple events simultaneously, it can use a single notification that directs the user to an interstitial screen. This screen summarizes these events, and provides paths for the user to dive deeply into the app. Notifications of this style are called indirect notifications.
当您的应用程序需要同时呈现多个事件的信息,它可以使用一个单一的通知,将用户引导到一个插播式界面。这个界面总结了这些事件,并为用户提供跳转到应用程序更深的路径。这种风格的通知被称为间接通知。

Unlike standard (direct) notifications, pressing Back from an indirect notification’s interstitial screen returns the user to the point the notification was triggered from—no additional screens are inserted into the back stack. Once the user proceeds into the app from its interstitial screen, Up and Back behave as for standard notifications, as described above: navigating within the app rather than returning to the interstitial.
与标准(直接)通知不同的是,从一个间接通知的插播式界面回退,将返回到用户接收该通知时所在的界面,没有额外的界面触发插入到回退堆栈中。当用户从其插播式界面进入应用程序后,向上和回退的响应与上述的标准通知一致:在应用程序中导航,而不再返回到插播式界面。

For example, suppose a user in Gmail receives an indirect notification from Calendar. Touching this notification opens the interstitial screen, which displays reminders for several different events. Touching Back from the interstitial returns the user to Gmail. Touching on a particular event takes the user away from the interstitial and into the full Calendar app to display details of the event. From the event details, Up and Back navigate to the top-level view of Calendar.
例如,假设一个用户在Gmail中收到一个来自日历的间接通知。点击这个通知,进入到显示许多不同事件提醒的插播式界面。此时如果回退将从插播式界面返回用户的Gmail。而点击其中一个事件将离开改插播式界面跳转到日历应用中显示该事件的详细介绍。在事件的细节界面,向上或回退的操作将跳转到日历界面层级关系中的顶层界面。

Pop-up notifications
弹出通知

Pop-up notifications bypass the notification drawer, instead appearing directly in front of the user. They are rarely used, and should be reserved for occasions where a timely response is required and the interruption of the user’s context is necessary. For example, Talk uses this style to alert the user of an invitation from a friend to join a video chat, as this invitation will automatically expire after a few seconds.
弹出通知绕过通知抽屉,直接作为显示的顶层出现在用户面前。虽然它们很少被使用,但是当有一个需要及时响应的请求并且有必要中断用户的上下文时,你仍是需要它们的。例如,Talk就使用这种方式来提醒用户他的朋友发来了视频聊天的邀请,因为这个邀请将在发起后几秒钟自动结束。

In terms of navigation behavior, pop-up notifications closely follow the behavior of an indirect notification’s interstitial screen. Back dismisses the pop-up notification. If the user navigates from the pop-up into the notifying app, Up and Back follow the rules for standard notifications, navigating within the app.
在导航行为方面,弹出式通知与间接通知的插播式界面的响应几乎是一致的。回退键将销毁弹出式通知。如果用户从弹出通知跳转到发出通知的应用程序,那么向上和回退的响应将和普通通知一样,在应用程序内进行导航。

Navigation Between Apps
在应用程序间导航

One of the fundamental strengths of the Android system is the ability for apps to activate each other, giving the user the ability to navigate directly from one app into another. For example, an app that needs to capture a photo can activate the Camera app, which will return the photo to the referring app. This is a tremendous benefit to both the developer, who can easily leverage code from other apps, and the user, who enjoys a consistent experience for commonly performed actions.
安卓系统的一个基本特点是应用程序间能够互相启动,用户可以从一个应用程序直接跳转到另一个应用程序。例如,一个应用程序需要拍照时可以启动相机应用程序,而后相机将拍摄的照片返回给该应用程序。无论对开发者还是用户,这都是一个巨大的好处。开发者可以很容易地使用其他应用程序中的代码,而用户可以有很好的一致性体验。

To understand app-to-app navigation, it’s important to understand the Android framework behavior discussed below.
要了解应用程序间的导航,重要的是了解下面要讲到的安卓框架行为。

Activities, tasks, and intents
活动,任务,和意图

In Android, an activity is an application component that defines a screen of information and all of the associated actions the user can perform. Your app is a collection of activities, consisting of both the activities you create and those you re-use from other apps.
在安卓系统中,活动是一个应用程序组件,它定义了一个界面的信息和所有相关的用户可执行操作。你的应用程序是一系列的活动的集合,包括你创建的活动和那些你对其他应用程序进行了重新使用的活动。

A task is the sequence of activities a user follows to accomplish a goal. A single task can make use of activities from just one app, or may draw on activities from a number of different apps.
任务是用户为了完成某一目标所执行的一系列活动的栈(集合)。一个单一的任务可以只使用一个应用程序中的活动,也可以使用多个应用程序中的活动。

An intent is a mechanism for one app to signal it would like another app’s assistance in performing an action. An app’s activities can indicate which intents they can respond to. For common intents such as “Share”, the user may have many apps installed that can fulfill that request.
意图是应用用于标识自己需要另一个应用的援助来执行某一个动作的机制。一个应用程序的活动可以表明自己能够响应哪些意图。常见的意图有“分享”,用户可能有许多已安装的应用程序可以响应并完成该要求。
Example: navigating between apps to support sharing
例如:在应用程序之间导航以支持共享

To understand how activities, tasks, and intents work together, consider how one app allows users to share content by using another app. For example, launching the Play Store app from Home begins new Task A (see figure below). After navigating through the Play Store and touching a promoted book to see its details, the user remains in the same task, extending it by adding activities. Triggering the Share action prompts the user with a dialog listing each of the activities (from different apps) which have registered to handle the Share intent.
要了解活动(activity),任务和意图如何一起工作,我们考虑一下:一个应用程序如何允许用户使用另一个应用程序来共享内容。例如,从主页面中启动Play Store 开始新任务A(见下图)。在Play Store 中点击一本推荐的书,以查看它的详情。 此时用户仍然在同一个任务中,并通过增加activity来扩展任务。触发共享功能将会提示用户一个对话框,其中列出所有声明了可以处理该共享意图的activity(从不同的应用程序)。

When the user elects to share via Gmail, Gmail’s compose activity is added as a continuation of Task A—no new task is created. If Gmail had its own task running in the background, it would be unaffected.
当用户选择共享通过Gmail,Gmail的写(邮件)activity被添加为任务A的一个延续,而不是新建一个任务。如果Gmail本来有自己的任务在后台运行,它将不受影响。

From the compose activity, sending the message or touching the Back button returns the user to the book details activity. Subsequent touches of Back continue to navigate back through the Play Store, ultimately arriving at Home.
从撰写activity,发送邮件或点击回退按钮都将返回书的详细信息activity。随后的回退操作将在Play Store中导览,直到回到手机主界面。

However, by touching Up from the compose activity, the user indicates a desire to remain within Gmail. Gmail’s conversation list activity appears, and a new Task B is created for it. New tasks are always rooted to Home, so touching Back from the conversation list returns there.
然而,如果用户在写activity中点击向上按键,则表示希望停留在Gmail。这时会显示Gmail的会话列表activity,并且将为它新建一个任务B。所以从对话列表中返回的话,将返回原来的地方(写activity)。

Task A persists in the background, and the user may return to it later (for example, via the Recents screen). If Gmail already had its own task running in the background, it would be replaced with Task B—the prior context is abandoned in favor of the user’s new goal.
任务A仍保留在后台,用户可以随时返回它(比如,通过Recents面板)。如果Gmail已经有自己的任务在后台运行,它将被任务B取代,并且先前的上下文将被舍弃以支持用户的新目标。

When your app registers to handle intents with an activity deep within the app’s hierarchy, refer to Navigation into Your App via Home Screen Widgets and Notifications for guidance on how to specify Up navigation.
当你的应用程序所注册处理意图的Activity处于应用程序的层次结构中比较深的层次,参考Navigation into Your App via Home Screen Widgets and Notifications来学习如何制定浏览。

0 0