Android BottomSheet是一种视图,用作移动应用程序中的辅助表面。此组件是android设计支持库的一部分,用于公开更多数据或信息,菜单,深层链接内容,并代替对话框。它从应用程序屏幕的底部向上滑动而出现在屏幕上,并且用户在接收到信息后可以将其隐藏。人们可以在Google Maps,音乐播放器等应用程序中轻松注意到BottomSheets。在现代Android应用程序中,BottomSheets有两种类型:
- 持久底页
- 模态底页
持久底页
Persistent BottomSheet会像活动/片段布局上显示的任何其他视图一样显示Android底部表。顾名思义,它的存在是持久的,即它与应用程序主UI区域共存。它通过显示相关的应用程序内容来方便用户,并允许在该区域中同时进行交互。开发人员使用此BottomSheet来显示菜单,任何种类的辅助内容或该应用程序的其他支持内容。
Google Maps中的Persistent BottomSheet:
模态底页
这种BottomSheet的外观类似于alert-dialog或dialog片段。之所以给这个名字起名,是因为它的行为和外观与Modals相似。与Persistent BottomSheet不同,当用户请求某些操作时,它从屏幕底部出现。激活后,它会遮盖主应用程序的活动/片段。工作表内容的海拔高度高于应用程序(默认为16dp ),并且包含与用户做出的操作请求相对应的选项列表或其他应用程序的深层链接内容。
Google云端硬盘中的Modal BottomSheet(出现在单击“ +”图标以向驱动器中添加新项目时出现):
差异表
Persistent BottomSheet |
Modal BottomSheet |
---|---|
Display content related to the application or current activity. | Display content of other applications that are interlinked with the current app. |
Always present at bottom of the app screen and display some content. When activated/clicked, it shows complete information. | Appear on the screen when a user clicks on certain action buttons. While poping up on the screen, it replaces the already present menu or dialogs. |
It is a part of the activity view layout. | It is not a part of an activity view layout but appears dynamically when the user demands. |
Integrated into the app in order to display supporting content. | Slides up from the bottom of the screen when needed. |
The elevation of its appearance is the same as that of the application’s content. | Its appearance has a higher elevation than the application’s content. Android dims and blocks the interaction with the main app to shift the focus of the user. |
BottomSheetBehavior(a kind of layout_behavior) is applied to a child of CoordinatorLayout in order to make it a Persistent bottom sheet. | To make a bottom sheet of Modal design, BottomSheetDialogFragment is used on top of the Fragment support library. It renders the fragment acting as a dialog to a Modal bottom sheet. |
To see more or less content, it can be dragged upward or downward respectively. | Expose its content by dragging it vertically upwards. Tap the content outside the dialog to dismiss the bottom sheet. |
To control its appearance, certain kinds of states are present such as STATE_COLLAPSED, STATE_EXPANDED, STATE_DRAGGING, STATE_SETTLING, and STATE_HIDDEN. | No such states are present in it as the appearance is similar to an alert-dialog or dialog fragment. |