How can I show options after LongClick?

I need to program something like the image:

example

When I long click a item in a ListView two options appear in the toolbar, to delete the item or cancel the action.

I want to make exactly like that, I do not want a context menu (which I know how to do).

Is it possible to do this with simple code? If no, can I accomplish that manipulating the toolbar? How can I do that?

PS: I can only use native code.

1 answer

  • answered 2018-11-05 16:18 Ramesh Yankati

    You need to use contextual Action Mode Over Toolbar.For Using Action Mode we need to extend our class with ActionMode.Callback. Its a Callback interface for action modes. Supplied to startSupportActionMode(Callback) (Callback)}, a Callback configures and handles events raised by a user’s interaction with an action mode.You need to override following method.

        onCreateActionMode(ActionMode, Menu) once on initial creation.
        onPrepareActionMode(ActionMode, Menu) after creation and any time the ActionMode is 
        invalidated.
        onActionItemClicked(ActionMode, MenuItem) any time a contextual action button is 
        clicked.
        onDestroyActionMode(ActionMode) when the action mode is closed.