Ultimate Guide to Material 3 Menus in Android XML (2025 Tutorial + Examples)

Ultimate Guide to Material 3 Menus in Android: Tutorial & Examples for 2025 🚀

Overview 📖

Material 3 Menus display a list of choices on temporary surfaces, triggered by user interactions like buttons or long presses. This guide covers two variants—Dropdown (overflow, context, popup, list popup window) and Exposed Dropdown—their implementation, accessibility, and theming for 2025. 🗳️

Overview of Material 3 Menu

Design and API Documentation 🔗

Using Menus 🤖

Add the Material Components for Android library dependency to use Material 3 Menus. See the Get Started guide. Use XML menu resources for Dropdown menus or TextInputLayout with AutoCompleteTextView for Exposed Dropdown menus. Use a Theme.Material3.* theme for proper styling. 🛠️

Making Menus Accessible ♿

Menus are readable by TalkBack, with text labels auto-provided. For Exposed Dropdown menus, use label and helper text in TextInputLayout. Set android:contentDescription for custom accessibility needs. See the Android accessibility guide. 🗣️

Behavior and Configuration 🎬

Configure Dropdown menus via XML resources or programmatically. For Exposed Dropdown, set items via adapters or setSimpleItems. Handle selections with listeners. Example:

      
val popup = PopupMenu(context, anchorView)
popup.menuInflater.inflate(R.menu.popup_menu, popup.menu)
popup.setOnMenuItemClickListener { /* Handle selection */ }
popup.show()
      
      
    

Menu Variants 🌟

Material 3 Menus come in two variants: Dropdown (overflow, context, popup, list popup window) and Exposed Dropdown, each suited for different selection scenarios. 🗳️

  1. Dropdown Menu: Temporary list triggered by actions.
  2. Exposed Dropdown Menu: Text field with dropdown options.
Menu variants: dropdown, exposed dropdown

Dropdown Menu 📋

Dropdown Menus display options via overflow, context, popup, or list popup window, triggered by icons or actions. 📋

Dropdown Menu (Popup)

Dropdown Menu Example 💻

API and source code:

The following example shows a popup menu triggered by a button.

      

      
    
      


    
    

      
      
    
      
val button = findViewById
      
    

Anatomy and Key Properties 📏

A dropdown menu includes a container, list items, and optional icons or dividers. 📋

Dropdown Menu anatomy diagram
  • Container: Temporary surface, 3dp elevation.
  • List Items: Selectable options. ✍️
  • Icons: Optional leading/trailing icons. 🖼️

Exposed Dropdown Menu 🖹

Exposed Dropdown Menus combine a text field with a dropdown list, using TextInputLayout and AutoCompleteTextView. 🖹

Exposed Dropdown Menu

Exposed Dropdown Menu Example 💻

API and source code:

The following example shows a filled exposed dropdown menu.

      

    

      
      
    
      
val textField = findViewById(R.id.menu)
val autoComplete = textField.editText as MaterialAutoCompleteTextView
autoComplete.setSimpleItems(arrayOf("Item 1", "Item 2"))
autoComplete.setText("Item 1", false)
      
      
    

Anatomy and Key Properties 📏

An exposed dropdown menu includes a text field, dropdown container, and selection text. 🖹

Exposed Dropdown Menu anatomy diagram
  • Container: TextInputLayout, holds dropdown.
  • Label: Field hint. ✍️
  • Selection Text: Selected item in AutoCompleteTextView. 📋
  • Trailing Icon: Dropdown toggle. 🖼️

Attributes (All Variants) 📋

Element Attribute Related method(s) Default value
Dropdown Container android:popupMenuBackground N/A ?attr/popupMenuBackground
android:popupElevation N/A 3dp
Dropdown Text android:title Menu.add, Menu.getItem N/A
Exposed Dropdown Container app:dropDownBackgroundTint setDropDownBackgroundTint colorSurfaceContainer
Exposed Dropdown Text android:text setText, getText null

Styles 🎨

  • Popup Menu: Widget.Material3.PopupMenu
  • Exposed Dropdown (Filled): Widget.Material3.TextInputLayout.FilledBox.ExposedDropdownMenu
  • Exposed Dropdown (Outlined): Widget.Material3.TextInputLayout.OutlinedBox.ExposedDropdownMenu
  • Default style theme attribute: ?attr/popupMenuStyle, ?attr/textInputStyle

See the full list of menu styles and text field styles. 🔗

Theming Menus 🖌️

Material Theming customizes menu typography, colors, and shapes. 🎨

Themed Dropdown Menu

Theming Example 💻

Theming example for dropdown menus:

      





      
      
    

FAQ ❓

What are Material 3 Menus? 🤔

Temporary surfaces displaying a list of choices. ✅


How many menu variants are there? 🔢

Two variants: Dropdown and Exposed Dropdown. 🗳️


When to use Exposed Dropdown Menus? 🖋️

Use for selections within a text field, like forms. 🖹


How to make menus accessible? ♿

Use auto-provided labels or custom contentDescription; add labels for Exposed Dropdown. 🗣️


Can I customize menu appearance? 🎨

Yes, theme colors, typography, and shapes via res/values/styles.xml. 🖌️


How to add the Material 3 library? 📦

Include the Material Components for Android library. See the Get Started guide. 🛠️


Are there updates for 2025? 🗓️

This guide reflects 2025 Material 3 standards for menus. 🚀

Comments

Popular posts from this blog

Creating Beautiful Card UI in Flutter

Master Web Development with Web School Offline

Jetpack Compose - Card View