How can you implement such a FloatingActionButton in a Fragment so that when you click on it, the context menu pops up in the same position as the button.

enter image description here

  • Catch the click event and display popupMenu - Yuriy SPb

1 answer 1

In the PopupMenu constructors, the second parameter is the view, next to which the menu should be displayed. Try this:

@Override public void onClick(View view) { popupMenu = new PopupMenu(MainActivity.this, view); // TODO setOnDismissListener(), setOnMenuItemClickListener() popupMenu.inflate(R.menu.popup_menu); popupMenu.show(); }