The Fiori List Popup Window (Dropdown Menu)¶
The SDK provides a Fiori-themed dropdown menu called FioriListPopupWindow and a companion OverflowButton that can be used together to create overflow menus. The FioriListPopupWindow extends the functionality of the standard ListPopupWindow class, providing customization options for menu items. The OverflowButton is a Fiori themed MaterialButton designed for triggering the display of the overflow menu. Any view can be used as an anchor for the FioriListPopupWindow in case the OverflowButton is not needed.

Usage¶
The FioriListPopupWindow needs a few things to make it work:
- A list containing items of type
FioriMenuItemwhich represent the menu items. - A
Viewto use as its anchor (for display positioning). - A callback to be invoked when a menu item is clicked.
- A
Context, which is usually theActivity's or anchor view's context.
Setting up the Menu Items¶
Each item in a list is a FioriMenuItem that supports a text, enabled state, leading icon, trailing icon, and trailing text. If a FioriMenuItem has both trailing text and trailing icon, then FioriListPopupWindow will internally give the trailing icon precedence over the trailing text.
val menuItems : ArrayList<FioriMenuItem?> = arrayListOf(
FioriMenuItem(
text = "View More",
leadingIcon = R.drawable.ic_sap_icon_browse_folder
),
FioriMenuItem(
text = "Edit",
leadingIcon = R.drawable.ic_sap_icon_edit,
trailingIcon = R.drawable.ic_sap_icon_accept
),
null,
FioriMenuItem(
text = "Save/Copy",
leadingIcon = R.drawable.ic_sap_icon_save,
trailingText = "\u2318C"
)
)
Note: If a slot in the menu item list is null, then
FioriListPopupWindowwill treat it as a divider.
Anchoring the Dropdown to the Toolbar¶
A common use case is a dropdown being launched from the toolbar. In this example we set up the ListPopupWindow with a ListPopupWindowConfig to adjust the offset and set the maximum visible items before the dropdown becomes scrollable. A ListPopupWindowConfig object tells FioriListPopupWindow how the dropdown should look and behave.
val listPopupWindowConfig = ListPopupWindowConfig(
resources.getDimension(R.dimen.app_bar_menu_horizontal_offset),
resources.getDimension(R.dimen.app_bar_menu_vertical_offset),
maxVisibleItems
)
val dropdown = FioriListPopupWindow(
this,
anchorView,
{ selectedItem = it },
menuItems,
selectedItem,
listPopupWindowConfig,
)
toolbar = findViewById(R.id.toolbar)
toolbar.title = "Dropdown Menu"
if (!toolbar.menu.hasVisibleItems()) {
toolbar.inflateMenu(R.menu.custom_menu)
}
val menuItem = toolbar.menu.getItem(0)
val overflowIconButton = OverflowButton(this)
overflowIconButton.icon = ResourcesCompat.getDrawable(
resources, com.sap.cloud.mobile.fiori.R.drawable.ic_sap_icon_menu, theme
)
overflowIconButton.setOnClickListener{
dropdown.show()
}
// Important
menuItem.actionView = overflowIconButton
Anchoring the Dropdown to Any Other View¶
Since the FioriListPopupWindow is technically a standard DialogFragment, it can be launched by calling show(). Each menu item in the dropdown is represented by a FioriMenuItem data class instance which helps populate all the menu items. In this example, we are anchoring the dropdown to the OverflowButton.
val overflowButton: OverflowButton = findViewById(R.id.overflowButton)
overflowButton.setOnClickListener {
val dropdown = FioriListPopupWindow(
context = this,
anchorView = overflowButton,
onItemClick = { menuItem ->
// Handle menu item click
},
menuItems = menuItems
)
dropdown()
}
Customizing the Dropdown¶
You can customize the appearance and behavior of the overflow menu by configuring the ListPopupWindowConfig object passed to the FioriListPopupWindow constructor. Here are the customizable parameters:
horizontalOffset: The horizontal offset for the menu relative to the anchor view.verticalOffset: The vertical offset for the menu relative to the anchor view.maxVisibleItems: The maximum number of menu items to display before the menu becomes a scrolling menu.background: The background drawable resource for the popup menu.backgroundColorSelected: The background color for a selected menu item.labelTextSize: The text size for menu item labels.labelTextStyle: The text style for menu item labels.labelTextColor: The text color for menu item labels.leadingIconColor: The color for leading icons.trailingTextStyle: The text style for menu item trailing text.trailingIconColor: The color for menu item trailing icons.trailingTextColor: The text color for menu item trailing text.
You can adjust these parameters to achieve the desired appearance and behavior for your overflow dropdown menu.
Further Reading¶
Here are additional resources regarding menus: