Skip to content

Instantly share code, notes, and snippets.

@thoinv
Created July 4, 2022 02:45
Show Gist options
  • Save thoinv/24ea9b12c1f0f73e7282d597178f89c4 to your computer and use it in GitHub Desktop.
Save thoinv/24ea9b12c1f0f73e7282d597178f89c4 to your computer and use it in GitHub Desktop.
[Show Popup Menu] #android #popupmenu
PopupMenu popupMenu = new PopupMenu(MainActivity.this, button);
// Inflating popup menu from popup_menu.xml file
popupMenu.getMenuInflater().inflate(R.menu.popup_menu, popupMenu.getMenu());
popupMenu.setOnMenuItemClickListener(new PopupMenu.OnMenuItemClickListener() {
@Override
public boolean onMenuItemClick(MenuItem menuItem) {
// Toast message on menu item clicked
Toast.makeText(MainActivity.this, "You Clicked " + menuItem.getTitle(), Toast.LENGTH_SHORT).show();
return true;
}
});
// Showing the popup menu
popupMenu.show();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment