Customize Long-Press Message Menu
When a user long-presses a message in the chat UI, a pop-up window will appear, offering different options based on the current message type and conversation type. You can customize the display name, order, and even add or remove menu options.
Customize Menu Options in the Long-Press Message Pop-up
When the MessageListComponent
in the chat UI is about to display the long-press message menu, the following method is called. You can override this method to customize the menu:
public class CustomMessageListComponent extends MessageListComponent {
@Override
protected List<MsgAction<UiMessage>> beforeCreateMsgActionView(List<MsgAction<UiMessage>> msgActions) {
// Method 1: Remove the delete button
Iterator<MsgAction<UiMessage>> iterator = msgActions.iterator();
while (iterator.hasNext()) {
MsgAction<UiMessage> msgAction = iterator.next();
if (msgAction instanceof DeleteMsgAction) {
iterator.remove();
}
}
// Method 2: Add a custom CustomMsgAction at a specific position
msgActions.add(0, new CustomMsgAction());
return msgActions;
}
}
The default menu options can be distinguished by their class, as shown below:
Function | class |
---|---|
Reply | ReplyMsgAction |
Forward | ForwardMsgAction |
Copy | CopyMsgAction |
Delete | DeleteMsgAction |
Select | MultiMsgAction |