Message context menu is a menu that appears when a message is long-pressed. While you can entirely change the message menu using the Message click sample, follow this page to modify the menu to work in tandem with the standard message menu.
To customize the message context menu, you need to create a custom fragment.
The following are steps to creating the message context menu:
- Step 1: Edit the context menu list by inheriting from the fragment and implementing the
- Step 2: Retrieve the default menu list by calling the parent method.
- Step 3: You can add or remove items from the retrieved menu list.
- Step 4: The
makeMessageContextMenu()method provides the message that was long-pressed as an argument. Using this information, you can construct the necessary menu.
The following example shows an example of removing the
Edit option from the default menu and adding a
Resend menu option.
Menu items are differentiated using unique keys in the
DialogListItem. These keys are defined as string resources in
To edit the default menu list and add a new menu option, override the
To handle the action when the
resend option is clicked, override the
onMessageContextMenuItemClicked() method. In the sample below, it is resending the user message when this option is selected.
For an in-depth practical demonstration, see our sample code.